954,546 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

hi, shell /awk for getting echo the linenumber from log file

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.

hbmarar
Junior Poster
190 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

Hi All,

Forgot to mention my thanks for consideration.

Regards

harish

hbmarar
Junior Poster
190 posts since Apr 2005
Reputation Points: 10
Solved Threads: 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
Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

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

eggi
Posting Pro in Training
400 posts since Oct 2007
Reputation Points: 102
Solved Threads: 47
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You