{ 9 comments… read them below or add one }

1 codeguru February 26, 2009

That was pretty cool. Had problems understanding awk. The tip really enlightened me. Thanks

Reply

2 TrueColorTech June 1, 2009

Thanks for the tip, made things much easier.

Reply

3 sundar June 26, 2009

That’s a good tip! By the way, how to read a file, compare a field value then insert record in between using awk? Can you help? Thanks. :-)

Reply

4 andre January 19, 2010

Hi great article. One suggestion is that the file names in the awk scripts can be substituted for the standard input.

e.g. to get the number of lines in a file you could use

wc -l filename | awk ‘{ print $1 }’

Andre

Reply

5 varpal September 28, 2010

Can I compare two column in AWK

Reply

6 Ed Dagos September 16, 2011

Hi All,
Is it possible to find a pattern in the file and then print the previous 3 or 4 lines using awk/sed/grep ??
Regards,
Ed

Reply

7 Trupti October 1, 2011

Exactl, even I wanted to know the same. If anyone could help me with this. :)

Ed Dagos September 16, 2011

Hi All,
Is it possible to find a pattern in the file and then print the previous 3 or 4 lines using awk/sed/grep ??
Regards,

Reply

8 Vivek Gite October 1, 2011

Search for “foo” in data.txt and display 3 lines of leading context before matching line:

grep -B3 "foo" data.txt

The -A options display $NUM lines of trailing context after matching lines:

grep -A3 "foo" data.txt

Reply

9 Ed Dagos October 3, 2011

Thanks Vivek for your response. However, on Sun OS 5.10 Options -B and -A do not work. Would you mind to tell me what environment have you tested it.
Regards,
Ed

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 2 + 7 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: