[Gllug] Help with sed

Andrew Roberts ar at nooneishere.co.uk
Thu Aug 20 18:32:41 UTC 2009


2009/8/20 JLMS <jjllmmss at googlemail.com>


>
> 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/awkBEGIN { previous="NO";NEWLANG="pt"}$1=="[Lang_1]" {previous="YES"}$1 ~ /^Lang=/  && previous=="YES" { $1="Lang="NEWLANG;previous="NO";print}-----

Some alternative solutions:
  sed '/\[Lang_[0-9]\]/ { n; s/Lang=.*$/Lang=pt/ }' testfile
  awk '/\[Lang_[0-9]\]/ { print; getline; if ($0 ~ /Lang=/) $0="Lang=pt" }1'
testfile
Regards,
Andrew.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20090820/a549520e/attachment.html>
-------------- next part --------------
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list