Grep values from different lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep values from different lines
# 1  
Old 12-11-2011
Grep values from different lines

Hello,

I have a log file with many lines and I want to grep pcific values from spcific lines, I'm not sure if it is possible or not

Sample
16-11-11 19:54:13:INFO:Connection to device ip 20.10.11.23 took 0
16-11-11 19:54:13:FINE:Sending request.
16-11-11 19:54:13:INFO:Received response from device HTTP: 200 took 67

I want to grep the file and export the data ( 20.10.11.23 , 67 ) noting that.
  • it is always with the same sequence
  • the file contain more than one block as per the above example, it mean i must get the response time that found two line below the ip
Any suggestion
# 2  
Old 12-11-2011
what is your search criteria? IP?

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 12-11-2011
Try:
Code:
awk '/device ip/{printf $6" ";getline;getline;print $9}' file

This User Gave Thanks to bartus11 For This Post:
# 4  
Old 12-11-2011
Bartus11, Amazing...
Thank you ahamed101 I just wanted to grep the line where Bartus11 line solved it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep three consecutive lines if each lines contains certain string

say we have : 2914 | REQUEST | whatever 2914 | RESPONSE | whatever 2914 | SUCCESS | whatever 2985 | RESPONSE | whatever 2986 | REQUEST | whatever 2990 | REQUEST | whatever 2985 | RESPONSE | whatever 2996 | REQUEST | whatever 2010 | SUCCESS | whatever 2013 | REQUEST | whatever 2013 |... (7 Replies)
Discussion started by: Saumitra Pandey
7 Replies

2. Shell Programming and Scripting

Grep values on alternate lines

Hi, I have a file like 2011|ACC|.* 2013|ACC|.* 2011|ACCC|.* 2013|ACCC|.* 2013|ACCV|.* 2011|ADB|.* 2013|ADB|.* 2011|ADBC|.* 2013|ADBC|.* 2011|AIA|.* 2013|AXJ|.* 2013|NNN|.* .* represnts any alphanumeric characters after this part of the string I need a code to return only the... (3 Replies)
Discussion started by: sam05121988
3 Replies

3. Shell Programming and Scripting

Grep couple of consecutive lines if each lines contains certain string

Hello, I want to extract from a file like : 20120530025502914 | REQUEST | whatever 20120530025502968 | RESPONSE | whatever 20120530025502985 | RESPONSE | whatever 20120530025502996 | REQUEST | whatever 20120530025503013 | REQUEST | whatever 20120530025503045 | RESPONSE | whatever I want... (14 Replies)
Discussion started by: black_fender
14 Replies

4. Shell Programming and Scripting

AWK/GREP: grep only lines starting with integer

I have an input file 12.4 1.72849432773174e+01 -7.74784188610632e+01 12.5 9.59432114416327e-01 -7.87018212757537e+01 15.6 5.20139995965960e-01 -5.61612429666624e+01 29.3 3.76696387248366e+00 -7.42896194101892e+01 32.1 1.86899877018077e+01 -7.56508762501408e+01 35 6.98857157014640e+00... (2 Replies)
Discussion started by: chrisjorg
2 Replies

5. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

6. Shell Programming and Scripting

Print lines between two lines after grep for a text string

I have several very large file that are extracts from Oracle tables. These files are formatted in XML type syntax with multiple entries like: <ROW> some information more information </ROW> I want to grep for some words, then print all lines between <ROW> AND </ROW>. Can this be done with AWK?... (7 Replies)
Discussion started by: jbruce
7 Replies

7. Shell Programming and Scripting

AIX equivalent to GNU grep's -B and -A [print lines after or before matching lines]

Hi folks I am not allowed to install GNU grep on AIX. Here my code excerpt: grep_fatal () { /usr/sfw/bin/gegrep -B4 -A2 "FATAL|QUEUE|SIGHUP" } Howto the same on AIX based machine? from manual GNU grep ‘--after-context=num’ Print num lines of trailing context after... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

8. Shell Programming and Scripting

Grep and delete lines except the lines with strings

Hi I am writing a script which should read a file and search for certain strings 'approved' or 'removed' and retain only those lines that contain the above strings. Ex: file name 'test' test: approved package waiting for approval package disapproved package removed package approved... (14 Replies)
Discussion started by: vj8436
14 Replies

9. Shell Programming and Scripting

grep two values together.

Hi... I have a file abc.txt , havin more then 10,000 lines, each field separated by '#'. I want to grep 9914699895 and 999 from abc.txt I am trying cat abc.txt | grep 9914699895 | grep 999 but i am also getting data like 9991111111 or 9991010101 I want to grep "999" exactly and... (1 Reply)
Discussion started by: tushar_tus
1 Replies

10. Shell Programming and Scripting

grep and fetching lines after grep

suppose i have a file structure(serial file)-- ---------- ---------- --------- summery -------- ------ -------- finished ----- ------- i want to fetch lines from summery to finished i can get line of summery by grep command. but how can i fetch lines untill it reaches finished.probably... (2 Replies)
Discussion started by: arghya_owen
2 Replies
Login or Register to Ask a Question