help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sed or awk under XP in batch file (DOS box) - print $1 lines then de


From: Bob Proulx
Subject: Re: sed or awk under XP in batch file (DOS box) - print $1 lines then delete $1 lines from a file
Date: Thu, 1 May 2008 18:56:44 -0600
User-agent: Mutt/1.5.13 (2006-08-11)

John Bartley K7AAY wrote:
> > >   l=$(( $(wc -l < sourcefile.txt) / 4 ))
> > >   sed --in-place "1,${l}d" sourcefile.txt

> On May 1, 4:13 pm, John Bartley K7AAY <john.bart...@gmail.com>
> rebutted:
> 
> > Dangit, those don't work as you expected with XP and GNUwin32

XP!  Sorry.  I didn't see that in your subject line.  I would have
suggested something different then.  But actually I don't know how to
do it on MS and so will need to defer to others.  Sorry.

> > echo $(( $(wc -l < sourcefile.txt) / 4 ))
> > The system cannot find the file specified.

That is POSIX shell syntax.  If you have bash or ksh installed it can
do it from the command line.  I am using single quotes '...' here but
you will need to figure out how to convert them to double quotes for
XP.  I can't use double quotes in the shell because the $vars would be
expanded too soon.

  sh -c 'echo $(( $(wc -l < sourcefile.txt) / 4 ))'

And therefore perhaps something like this long one-liner.

  sh -c 'sed --in-place "1,$(( $(wc -l < sourcefile.txt) / 4 ))d" 
sourcefile.txt'

But if you don't have a POSIX standard shell available (e.g. bash or
ksh or ash or dash or posh or other) then it won't work.

> > l=$(( $(wc -l < sourcefile.txt) / 4 ))
> > The system cannot find the file specified.

Darn command.com!  Blech!

> > 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?

Sorry.  I don't know XP well enough to suggest a solution.

Good luck!
Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]