> > John Bartley K7AAY opened with:
> > > I need to print $1 lines from a file, and then delete that number of
> > > lines.
> > > $1 has been derived in the prior line with
> > > wc -l sourcefile.txt | awk '{$1 /= 4 ; $1 = int($1) ; print $1 }'


> On May 1, 4:02 pm, [EMAIL PROTECTED] (Bob Proulx) kindly replied:
>
>
>
> > That all looks okay.  But I would probably personally do it all in the
> > shell.  Try this:
>
> >   echo $(( $(wc -l < sourcefile.txt) / 4 ))
>
> > > I've tried numerous awk and sed statements, a la:
>
> > > sed -e -n "$1,p" sourcefile.txt > list.1
> > > sed -i "$1d" sourcefile.txt
> > > sed $1q list.txt > list.1 & sed -i $1d sourcefile.txt
> > > awk "{(FNR < $1); print}" sourcefile.txt > list.1
>
> > Try this:
>
> >   l=$(( $(wc -l < sourcefile.txt) / 4 ))
> >   sed --in-place "1,${l}d" sourcefile.txt
>
> > Bob


On May 1, 4:13 pm, John Bartley K7AAY <[EMAIL PROTECTED]>
rebutted:

> Dangit, those don't work as you expected with XP and GNUwin32
>
> echo $(( $(wc -l < sourcefile.txt) / 4 ))
> The system cannot find the file specified.
>
> l=$(( $(wc -l < sourcefile.txt) / 4 ))
> The system cannot find the file specified.
>
> sed --in-place "1,${l}d" sourcefile.txt
> sed: -e expression #1, char 7: extra characters after command

And, OBTW, this works when I stuff the numeric value of $1 into the
second line... but I can't seem to pass the value into that second
line. Ideas?

wc -l list.txt | awk '{$1 /= 4 ; $1 = int($1)+4 ; print $1 }'
csplit -f outfile- -n 1 list.txt $1 {2}



Reply via email to