[Ilugc] Help in AWK

  • From: zulfilee@xxxxxxxxxxxxx (zulfilee)
  • Date: Wed Feb 9 02:40:51 2005

Following is  a same solution with perl. See if it helps


perl -pi -e "s/(start[[:space:]]*)(hello)/\$1 HELLO/" Filename

perl -pi -e "s/^([[:space:]]*)start/\$1BEGIN/"  Filename

Cheers
Z

On Tuesday 08 February 2005 20:50, Mohan Kumar C wrote:

Hello Mr. Hari / ChennaiLug Team,

           I need your help in wrting a awk script, here's the scenario

1. Match a string pattern in a file and replace the matched pattern with a
new string in the file itself.

Ex:
          somefile.txt (contents of this file is as follows)
          ==========
        start         hello # start of the comment
        end          bye # end of the comment

Output Expected

         somefile.txt (contents of this file after execution of the script)
       ===========
        BEGIN     hello # start of the comment        end          bye #
end of the comment


find the string 'start \t' and replace it with BEGIN
===================================================
2. Match a string pattern in a file and replace a string with in the next
field of the matched pattern in the same file

Ex:
          somefile.txt (contents of this file is as follows)
          ==========
        start         hello # start of the comment
        end          bye # end of the comment

find the string 'start \t' and replace the following field (hello) ==> with
HELLO

Ouput Expected

          somefile.txt (contents of this file after execution of the
script) ==========
        start         HELLO # start of the comment
        end          bye # end of the comment


===================================================

Kindly reply on this ASAP

Regards,
-Mohan Kumar C



---------------------------------
 ALL-NEW Yahoo! Messenger - all new features - even more fun!
_______________________________________________
To unsubscribe, email ilugc-request@xxxxxxxxxxxxx with
"unsubscribe <password> <address>"
in the subject or body of the message.
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc

-- 
The highest sounds are hardest to hear. 
Going forward is a way to retreat. 
Great talent shows itself late in life. 
Even a perfect program still has bugs
                  -Tao of programming

Other related posts: