On Fri, Oct 21, 2005 at 08:45:38PM -0500, Martin McCormick wrote:
>       A Bourn shell script I am trying to run isn't behaving like I
> expected it to and I am not sure how to make it play nice.  There are
> a bunch of DNS zone files that need the bottom 6 lines chopped off and
> I hoped to do that with a while loop driven by the ls command.  In
> order to loose the bottom 6 lines, one must count all the lines,
> subtract 6 from that number and use the new value as a value for head.
> The problem occurs in the way awk is producing output in the loop.
> Here is the script:
> 
> #! /bin/sh
> filechop ()  {
> #This function takes one file at a time and removes the bottom 6 lines.
> #Get a single numerical value stating how many lines are in the file.
> zlength=`wc -l $zonename|awk '{print $1}'`
> shortlength=$(($zlength - 6))
> head -$shortlength $zonename >tmp.zone
> mv tmp.zone $zonename
> return 0
> }
> #main routine
> while zonename=`ls *.zone`;do
> filechop
> done
> 
>       Things go quite wrong when awk produces a line of output
> instead of one value per line which would drive the rest of the script.
> I have tried putting parentheses around the line reading
> 
> zlength=`(wc -l $zonename)|awk '{print $1}'`
> 
> And, I have moved the right parenthesis to include the awk call, but
> that changed nothing.
> 
>       Is there any way to get one value per iteration?
> 
> Thanks for any good ideas.
> 
> Martin McCormick WB5AGZ  Stillwater, OK 
> OSU Information Technology Division Network Operations Group
 
Not sure if I understood the problem correctly, but how about:

#! /bin/sh
filechop ()  {
  #This function takes one file at a time and removes the bottom 6 lines.
  #Get a single numerical value stating how many lines are in the file.
  zlength=`wc -l $zonename|awk '{print $1}'`
  shortlength=$(($zlength - 6))
  head -$shortlength $zonename >tmp.zone
  mv tmp.zone $zonename
  return 0
}
#main routine
for zonename in `ls *.zone`; do
  filechop;
done

Simo
-- 
:r ~/.signature

Attachment: signature.asc
Description: Digital signature

Reply via email to