[Wolves] Sed help.

chris procter chris-procter at talk21.com
Fri Jun 20 12:26:34 BST 2008


If your awking you can do:

awk 'BEGIN{i=""}{print "start " $0 "|grep -vir >
'http://' >> test" i ".txt"; i++}' < in.txt > out.txt

(replacing start with your start text obviously) 
which will produce test.txt test1.txt etc

or the simpler

awk '{print "start " $0 "|grep -vir > 'http://' >>
test" $NR ".txt"}' < tmp.txt

which will produce test1.txt test2.txt etc (i.e. the
first file has a number)

In awk $0 is the current line $NR is the number of the
current line.

I like awk, its far nicer then sed :)

chris


--- "Simon C. Burke" <simonb at geek-web.co.uk> wrote:

> 
> ----- Original Message ----- 
> From: "Ron Wellsted" <ron at wellsted.org.uk> 
> To: "Wolverhampton Linux User Group"
> <wolves at mailman.lug.org.uk> 
> Sent: Friday, 20 June, 2008 11:41:18 AM GMT +00:00
> GMT Britain, Ireland, Portugal 
> Subject: Re: [Wolves] Sed help. 
> 
> On Fri, Jun 20, 2008 at 11:28:48AM +0100, Simon C.
> Burke wrote: > In the end I replaced the sing quotes
> with double quotes and escaped them with the good
> old backslash. > Now I just need to find how to add
> tot he start. > > > ----- Original Message ----- >
> From: "Simon C. Burke" > To:
> wolves at mailman.lug.org.uk > Sent: Friday, 20 June,
> 2008 11:11:20 AM GMT +00:00 GMT Britain, Ireland,
> Portugal > Subject: [Wolves] Sed help. > > > I have
> a text file with some 18000 lines and i need to
> ammend something to the start and end. For the end I
> have: > > sed 's/$/Add Text to end"/g' myfile > >
> However the text I'm adding is: > > ' |grep -vir
> 'http://' >> test.txt > > > The issue I have is that
> how do I now escape the pipe and inverted comma's? >
> > Any idea's?? Glad you found a solution to your
> first problem There was an simpler solution : use a
> script file which you invoke with the -f switch (eg
> sed -f script.sed infile >outfile) This way you do
> not need to worry about shell escapes. The normal RE
> char for the begining of a line is the caret ^ HTH 
> 
> Thanks for that. I worked it out in the end, awk's a
> bit alien to me at the moment. so im really happy
> with what I have done so far. 
> The next issue was echoing an incrementing number
> into test.txt (ie test2.txt, test3.txt) and so
> forth. I was going to cheat and instead of awking
> the text to the end, still awk the front ut use a
> quick bash script to echo the end with the variable
> in. Ah well the scripts running now. 
> 
> Thanks for any time anyone spent on this. 
> 
> Regards, 
> 
> Simon B 
> > _______________________________________________
> Wolves LUG mailing list
> Homepage: http://www.wolveslug.org.uk/
> Mailing list: Wolves at mailman.lug.org.uk
> Mailing list home:
https://mailman.lug.org.uk/mailman/listinfo/wolves



      __________________________________________________________
Sent from Yahoo! Mail.
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html



More information about the Wolves mailing list