Something off the box: I got a log file of the pattern say like this :

             19876   Exception happened at heylog.php.
             19878   Argument missing

I need a shell script / awk which should get the file, read the line and should get me the line number displayed with that message in the line and then should replace it with a Fixed Markup text, like say it becomes like this once the print to screen is done:

            19876  Exception happened at heylog.php
            19878  Static Fixed known error

This line code does not print the line that i got from the above lines in the script. i took this from a googled example

  file = //some file manipulation
  line = // get the line number          
  # awk 'NR==$line{print;exit}' web.log.1
  //Above code awk ... does not get the $line while prints. how to get this $line. this is where i am stuck.

Hi All,

Forgot to mention my thanks for consideration.



You can have as many awk commands as you like

awk '
/Exception happened/ { print }
/Argument missing/ { print "19878 Static Fixed known error" }
{ print }' file.txt

Hey there,

The above comment is absolutely correct; just thought this might help a bit.

If you want to print out the line numbers on your matches just print NR within awk, like

'{print NR}'

or, since you want the whole line, too:

'{print NR,$0}'

Format to taste ;)

, Mike