Print lines before after pattern meacted


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print lines before after pattern meacted
# 1  
Old 05-17-2014
Print lines before after pattern meacted

Hi All,

Am trying to print pervious lines of the pattern matched, I was able to print pattern matched and the required data but don't know how to get the pervious line.


Code:
 ifconfig -a | grep  10.118.67.33 | sed -e 's/^[[: :]]*//' -e 's/[[: :]]*$//' | awk '{FS=" "; print $6}'

output I get is the ipaddress ie,
Code:
 10.118.67.33

what am looking is how to get the pervious line of this ipaddress... can someone please help me on this.


Many thanks
Ops
# 2  
Old 05-17-2014
The whole line before pattern?

Code:
ifconfig -a | awk '{a[++i]=$0;} /10.118.67.33/{print a[NR-1]}'

This User Gave Thanks to Aia For This Post:
# 3  
Old 05-17-2014
Thanks Aia. logic works perfectly. this what I was looking for and I was struggling to get pervious whole line.

Many Thank Again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print lines after matching two pattern

would like to print everything after matching two patterns AAA and BBB. output : CCC ZZZ sample data : AAA BBB CCC ZZZ (4 Replies)
Discussion started by: jhonnyrip
4 Replies

2. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

3. AIX

Grep a pattern and print following n lines

Hi all, I am struck with the below requirement. I need to grep a particular pattern in a file and then print next n lines of it for further processing. I have used the below code grep -A 3 "pattern" filename But it is throwing error as below. grep: illegal option -- A Can... (14 Replies)
Discussion started by: ssk250
14 Replies

4. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

5. Shell Programming and Scripting

Print/delete the lines between two pattern.

Hello, I am having hard time figuring out how to print/delete the lines between two pattern. Here is the part of the file nastran1.bdf: RBE3 48729 32232 123456 0.30000 123 59786 59787 60114 RBE3 48732 1330 123 0.30000 123 10107... (4 Replies)
Discussion started by: dragomir
4 Replies

6. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

7. Shell Programming and Scripting

Print lines before and after pattern match

I am using Solaris, I want to print 3 lines before pattern match pattern 5 lines after pattern match Pattern is abcd to be searched in a.txt. Looking for the solution in sed/awk/perl. Thanks .. Input File a.txt: ================= 1 2 3 abcd 4 5 6 7 8 (7 Replies)
Discussion started by: manuswami
7 Replies

8. Shell Programming and Scripting

print lines up to pattern excluding pattern

11 22 33 44 55 66 77 When pattern 55 is met, print upto it, so output is 11 22 33 44 (1 Reply)
Discussion started by: anilcliff
1 Replies

9. Shell Programming and Scripting

Print the above and below lines for the grep pattern.

Hi, i would like to get the above and below lines of the grep pattern . For ex : file as below: chk1- aaaa 1-Nov chk2 -aaaa ########## chk1-bbbbbb 1-Nov chk2-bbbbbb ######### my search pattern is date : 1-Nov i need the o/p as below chk1- aaaa 1-Nov (6 Replies)
Discussion started by: expert
6 Replies

10. Shell Programming and Scripting

print certain pattern from 2 lines

i have 2 lines comming out of a script o/p.below the line. 2008-10-14 05:47:05,551 INFO - LPBatch: 2008-10-14 05:47:05,575 INFO - Number of Intervals Not Inserted: 1 / 95 -------------------------------------------------------------------------- How to print the below o/p from the... (2 Replies)
Discussion started by: ali560045
2 Replies
Login or Register to Ask a Question