Re: 1st line w/regex only
From: Walter Briscoe (wbriscoe_at_ponle.demon.co.uk)
Date: 08/07/03
- Next message: Adam Price: "Re: bash and $"blah $var" syntax"
- Previous message: DukeNM: "Re: using tar and Storing backup log and list to seperate files."
- In reply to: Peter S Tillier: "Re: 1st line w/regex only"
- Next in thread: Alan Connor: "Re: 1st line w/regex only"
- Reply: Alan Connor: "Re: 1st line w/regex only"
- Reply: Peter S Tillier: "Re: 1st line w/regex only"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 7 Aug 2003 12:10:09 +0100
In message <bgss32$kaq$1$830fa7a5@news.demon.co.uk> of Thu, 7 Aug 2003
07:36:56 in comp.unix.shell, Peter S Tillier
<peter_tillier@despammed.com> writes
>Alan Connor wrote:
>[...]
>> Worked like a CHARM, Peter! I use sed to replace "regex" with the
>> contents of a shell variable when the conditions of an "if" loop are
>> met, run the script, then switch it back to "regex" with sed...
>>
>> Here's a little tweak I had to do to get it work, and I know that
>> this is so obvious to you that it didn't seem worth mentioning, but it
>> might help my fellow sed newbies out:
>>
>> $ sed -n -f AlanC01.sed AlanC01.dat > tmpfile ; mv tmpfile
>> AlanC01.dat
>>
>
>Yes, sorry, should have mentioned that.
I am inclined to think the point need not have been made.
I think it is wrong in that it uses "-n" which was not in the original
posting and destroys the functionality. I find "-n" is rarely needed in
simple scripts.
C:\WINNT\Temp\1stscrap) sed -f AlanC01.sed AlanC01.dat
1
2
regex 2
3
4
regex 4
5
6
C:\WINNT\Temp\1stscrap) sed -n -f AlanC01.sed AlanC01.dat
C:\WINNT\Temp\1stscrap)
The data is put at slightly less risk with:
cp AlanC01.dat tmpfile && sed -f AlanC01.sed tmpfile > AlanC01.dat && rm tmpfile
I am not sure how "sed -f foo < bar" compares with "sed -f foo bar" in
terms of setting an exit status. YMMV. In Microsoft's command.com, the
former would not set an error status and the latter might!
>
>
>> 1 {
>> x
>> s/.*//
>> x
>> }
[snip]
Many will prefer Peter's tutorial form to my own; I am not going to
change; I reckon effort ought to be required to acquire understanding.
He solved the class of problem in a beautiful fashion. I would not have
posted my solutions to the particular problem if I had seen that work.
I am surprised by Peter's assumption that the hold space might not be
empty when sed starts. The point is not explicitly covered in
http://www.opengroup.org/onlinepubs/007904975/utilities/sed.html
I infer it can only be empty. Can someone point at an implementation
where Peter's assumption is necessary? Can anyone justify it?
I look forward to Alan's next question when he has the "sed and awk"
book ;-) I think sed is to awk as assembler is to C!
-- Walter Briscoe
- Next message: Adam Price: "Re: bash and $"blah $var" syntax"
- Previous message: DukeNM: "Re: using tar and Storing backup log and list to seperate files."
- In reply to: Peter S Tillier: "Re: 1st line w/regex only"
- Next in thread: Alan Connor: "Re: 1st line w/regex only"
- Reply: Alan Connor: "Re: 1st line w/regex only"
- Reply: Peter S Tillier: "Re: 1st line w/regex only"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|