Need to delete previous line after successful seearch


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to delete previous line after successful seearch
# 1  
Old 10-30-2006
Need to delete previous line after successful seearch

i have a file in following pattreen

A:
Size = 10
B:
Size = 0
C:
Size = 220
D:
Size = 0

i want to Display only Charecters which have which have Size = 0

The Out put Should be
B:
D:

Can Some one Help
# 2  
Old 10-30-2006
Try...
Code:
$ cat file1
A:
Size = 10
B:
Size = 0
C:
Size = 220
D:
Size = 0

$ paste - - < file1
A:      Size = 10
B:      Size = 0
C:      Size = 220
D:      Size = 0

$ paste - - < file1 | awk '$NF == 0 { print $1 }'
B:
D:

# 3  
Old 10-30-2006
Hi Yogor

Can you please tell me what exactly paste - - < file1 means ?
although i see the out put you have mention still i am confusing the functionality of
- - ?? (double hyphen )
# 4  
Old 10-30-2006
nawk -f pb.awk myFile.txt

pb.awk:
Code:
!(FNR%2) && $NF == 0 { print a;next}
{a=$0}

# 5  
Old 10-30-2006
Code:
sed -n "N;/Size *= *0/{P;d;}" file

# 6  
Old 10-30-2006
Python alternative,simpler to understand
Code:
#!/usr/bin/python
data = open("input.txt").readlines()
for i in range(len(data)):
 	if data[i].startswith("Size = 0"):
 		print data[i-1].strip()

output:
Code:
B:
D:

# 7  
Old 10-31-2006
hi anbu can u explain this " sed -n "N;/Size *= *0/{P;d;}" "

hi anbu

can u explain this " sed -n "N;/Size *= *0/{P;d;}" "
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Advanced & Expert Users

How to find a string in a line in UNIX file and delete that line and previous 3 lines ?

Hi , i have a file with data as below.This is same file. But actual file contains to many rows. i want to search for a string "Field 039 00" and delete that line and previous 3 lines in that file.. Can some body suggested me how can i do using either sed or awk command ? Field 004... (7 Replies)
Discussion started by: vadlamudy
7 Replies

3. Shell Programming and Scripting

Remove previous line if next & previous lines have same 4th character.

I want to remove commands having no output. In below text file. bash-3.2$ cat abc_do_it.txt grpg10so>show trunk group all status grpg11so>show trunk group all status grpg12so>show trunk group all status GCPKNYAIGT73IMO 1440 1345 0 0 94 0 0 INSERVICE 93% 0%... (4 Replies)
Discussion started by: Raza Ali
4 Replies

4. Shell Programming and Scripting

Sed Comparing Parenthesized Values In Previous Line To Current Line

I am trying to delete lines in archived Apache httpd logs Each line has the pattern: <ip-address> - - <date-time> <document-request-URL> <http-response> <size-of-req'd-doc> <referring-document-URL> This pattern is shown in the example of 6 lines from the log in the code box below. These 6... (1 Reply)
Discussion started by: Proteomist
1 Replies

5. 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

6. Shell Programming and Scripting

Delete File Only If Successful Transfer..

Hi. I have this shell script for ftp.. ftp -n 12.34.5.67 << EOF user username password cd LOCAL/inbox bin get JAN_Total.gz # del JAN_Total.gz EOF how do i modify the commented part i.e. del JAN_Total.gz only if that JAN_Total.gz has been successfully transfered to the local... (8 Replies)
Discussion started by: aimy
8 Replies

7. Shell Programming and Scripting

Find pattern a delete previous 5 lines

Hi guys, i have the follow problem i need to delete 10 row before the pattern and 1 after and the pattern row itself. file looks like: frect 9.8438 25.8681 10.625 25 . dynprop \ (# \ (call fox_execute(__self))) \ (FOX_VAR_29 \ ... (4 Replies)
Discussion started by: EjjE
4 Replies

8. Shell Programming and Scripting

Need to delete previous lines

Need to delete the line which is directly above any line which has 3 fields in it. one two three one two three four five six four five six seven eight nine seven eight nine one two three should output: one two three (7 Replies)
Discussion started by: linuxkid
7 Replies

9. UNIX for Advanced & Expert Users

delete line from file if successful partial string found

Id like to delete a line from a file using (preferably a single line unix command) if it contains a certain string pattern. If line contains "abcdef" then delete that line. Help greatly appreciated. (7 Replies)
Discussion started by: cronjob78
7 Replies

10. Shell Programming and Scripting

Delete original wav file if lame was successful encoding.

In a bash script: src=”cooltrack.wav” dst=”cooltrack.mp3” lame $src $dst I would like to add some line that would delete the source wav file like: rm $src but I would like this only if the encoding was successful. What should I include before deleting the original to check that the... (2 Replies)
Discussion started by: Aia
2 Replies
Login or Register to Ask a Question