0

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.

Edited by mike_2000_17: Fixed formatting

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by eggi
0

Hi All,

Forgot to mention my thanks for consideration.

Regards

harish

0

You can have as many awk commands as you like
Eg

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

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.