[Gllug] Help with sed

JLMS jjllmmss at googlemail.com
Thu Aug 20 14:40:44 UTC 2009


On Thu, Aug 20, 2009 at 2:53 PM, Dan Kolb<gllug at eco.li> wrote:
> On Thu, Aug 20, 2009 at 01:21:11PM +0100, Christopher Mocock wrote:
>> Hi,
>>
> [snip sed]
>>
>> I haven't refined that but it's the general idea I was trying. It's the
>> newlines that seem to be the problem.
>
> sed will change text on a line-by-line basis. So, from the man page:
>
>     Normally, sed cyclically copies a line of input, not including its termi-
>     nating newline character, into a pattern space, (unless there is some-
>     thing left after a `D' function), applies all of the commands with ad-
>     dresses that select that pattern space, copies the pattern space to the
>     standard output, appending a newline, and deletes the pattern space.
>
>
>
> So, for what you want, you'll need some thing else. I'm going to suggest 'ed',
> and leave the ed script as an exercise for another reader.
>
> Dan

Why not use a language created to deal with this kind of problems?
Perl and awk small scripts can be put in place to deal with this in
short time and IMHO are more legible than other alternatives.

-----
#!/bin/awk
BEGIN { previous="NO";NEWLANG="pt"}
$1=="[Lang_1]" {previous="YES"}
$1 ~ /^Lang=/  && previous=="YES" { $1="Lang="NEWLANG;previous="NO";print}
-----

or something of the sort.

More elegant solutions will surely follow.
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list