Computing.Net > Forums > Programming > Print PreviousLine Using AWK?

Print PreviousLine Using AWK?

Reply to Message Icon

Original Message
Name: vinodjadye
Date: July 11, 2007 at 12:40:46 Pacific
Subject: Print PreviousLine Using AWK?
OS: Linux
CPU/Ram: Intel
Model/Manufacturer: Intel
Comment:

Hi,
I need to search the string in a file & then print the 12th line before the line where this string occurs (so basically print 12th line previous to this line). I need to know how can i do this using awk?
if there is any other way anyone can suggest i would be glad.


Vinod


Report Offensive Message For Removal

Response Number 1
Name: Mechanix2Go
Date: July 12, 2007 at 02:11:03 Pacific
Subject: Print PreviousLine Using AWK?
Reply: (edit)

I've been told there's a 'unix provider' for NT. [cyjwin?] And I guess I should get it and learm something.

Is the an 'NT provider' for unix?

anyone?


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 2
Name: ghostdog
Date: July 12, 2007 at 04:19:04 Pacific
Subject: Print PreviousLine Using AWK?
Reply: (edit)

here's one way
[code]
awk 'NR==FNR{ array[++c]=$0;next }
/search_string/ {print array[FNR-12]}
' "file" "file"
[/code]


Report Offensive Follow Up For Removal

Response Number 3
Name: Razor2.3
Date: July 12, 2007 at 21:12:54 Pacific
Subject: Print PreviousLine Using AWK?
Reply: (edit)

Mechanix2Go Is the an 'NT provider' for unix?

There's Wine


Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: July 13, 2007 at 00:26:23 Pacific
Subject: Print PreviousLine Using AWK?
Reply: (edit)

Hi Razor2.3

I forgot about WINE. I tried it way back when, maybe Mandrake 5x. It was shakey. Hopefully ut has improved in the interim.


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 5
Name: vinodjadye
Date: July 19, 2007 at 16:50:24 Pacific
Subject: Print PreviousLine Using AWK?
Reply: (edit)

Hi,
I am pasting the contents of the file below. I will get similar occurances more than 50 times in one file. I need to search for the string "End the test" and then print 11th or 12th line before this line (the one with timestamps). Please test your code & send it to me.
Thx in advance


Timestamp: Wed Jul 18 04:04:23 PM EDT 2007

Starting Traffic for 20 seconds...
Frame Size: 100
2/3 -> TX Frames: 1132112
2/3 -> RX Frames: 1132112
2/3 -> RX Min Latency: 314.02 usec
2/3 -> RX Max Latency: 44480.08 usec
2/3 -> RX AVG Latency: 6103.62 usec
2/3 -> 2/3 Loss: 0
2/3 -> 2/3 Loss Ratio %: 0.000000000

End the test, we are at max rate: 5.133056640625

Frame Sizes (bytes): 100
Rate (%): 5.13
Avg Latency (usec): 6103.62
Min Latency (usec): 314.02
Max Latency (usec): 44480.08


Vinod


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Print PreviousLine Using AWK?

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software