return previous line for pattern match


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers return previous line for pattern match
# 1  
Old 06-26-2006
return previous line for pattern match

Hi,

Need some idea on file processing, I have file like below,

Code:
Processing al sources ...
...No value found : 
CHECK. 
Completed comparing all  sources.
Comparing schedulers...
Processing al targets ...
...No value found :

From above I need to extract the line where "No value found" is available, which is simple, but I also wanna print the line before i.e
Code:
Processing al sources ...
...No value found : 
Processing al targets ...
...No value found :

Can sometell me how to go about this ?

Thanks
# 2  
Old 06-26-2006
You never mentioned your OS. If you have GNU grep, the use

Code:
grep -B 1 "No value found" file

# 3  
Old 06-26-2006
If your grep has no -B (Aix hasn't) then:
Code:
sed -n -e 'N; /No Value Found/p' yourfile.txt

cheers
# 4  
Old 06-26-2006
sorry guys, didn't give enough information,this is in suse linux,

sed -n -e 'N; /No match/p' $1 worked perfect.... thanks..

Last edited by braindrain; 06-26-2006 at 12:40 PM..
# 5  
Old 12-08-2008
Hi,
i tried
sed -n -e 'N; /No Value Found/p' yourfile.txt

but it only prints the previous line for the first match only.
thereafter only matching lines are printed and not their previous lines.

Thanks,
-srinivas yelamanchili
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk or sed to print the character from the previous line after the regexp match

Hi All, I need to print the characters in the previous line just before the regular expression match Please have a look at the input file as attached I need to match the regular expression ^ with the character of the previous like and also the pin numbers and the output file should be like... (6 Replies)
Discussion started by: kshitij
6 Replies

2. Shell Programming and Scripting

How to delete the previous line after pattern match?

Team, I am writing a shell script to perform few health checks of the system, where I need to delete the previous line in the text file after pattern match using sed (or) awk. Could you please help me out on this? For example, <td> <td style=color:green align=center> </td> </tr>... (6 Replies)
Discussion started by: Nagaraj R
6 Replies

3. AIX

Print nth previous line after match

Please help me print nth line after match awk or sed one line command. (3 Replies)
Discussion started by: sushma123
3 Replies

4. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

5. Shell Programming and Scripting

How to print previous line of multiple pattern matched line?

Hello, I have below format log file, Comparing csv_converted_files/2201/9747.1012H67126.5077292103609547345.csv and csv_converted_files/22019/97447.1012H67126.5077292103609547345.csv Comparing csv_converted_files/2559/9447.1012H67126.5077292103609547345.csv and... (6 Replies)
Discussion started by: arvindshukla81
6 Replies

6. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies

7. Shell Programming and Scripting

Pattern match exclusive return pattern/variable

I have an application(Minecraft Server) that generates a logfile live. Using Crontab and screen I send a 'list' command every minute. Sample Log view: 2013-06-07 19:14:37 <Willrocksyea1> hello* 2013-06-07 19:14:41 <Gromden29> hey 2013-06-07 19:14:42 Gromden29 lost connection:... (1 Reply)
Discussion started by: gatekeeper258
1 Replies

8. Shell Programming and Scripting

Delete line with match and previous line quoting/escaping problem

Hi folks, I've list of LDAP records in this format: cat cmmac.export.tmp2 dn: deviceId=0a92746a54tbmd34b05758900131136a506,ou=devices,ou=customer,ou=nl,o=upc cmmac: 00:13:11:36:a5:06 dn: deviceId=0a92746a62pbms4662299650015961cfa23,ou=devices,ou=customer,ou=nl,o=upc cmmac:... (4 Replies)
Discussion started by: tomas.polak
4 Replies

9. Shell Programming and Scripting

Append next line to previous line when one pattern not found

Hi, I need help for below scenario.I have a flat file which is having records seperated by delimiters which will represent each record for oracle table.My Control file will consider each line as one record for that table. Some of the lines are aligned in two/three lines so that records are... (4 Replies)
Discussion started by: kannansr621
4 Replies

10. Shell Programming and Scripting

return the previous line

Hello friends , I am doing the following command, but it is not wise to all files. for temp in `find ./CSV/ -name "*.txt"` do sed -n -e 'N; /*Main End/p' $temp done Its give me the correct output for some files , but not for all files. I mean some files contains the... (12 Replies)
Discussion started by: user_prady
12 Replies
Login or Register to Ask a Question