sed logic before deleting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed logic before deleting
# 1  
Old 05-01-2009
sed logic before deleting

FileA
NAME STATE CITY
---- ---- -----
abc ca ca
bcc ny ny
def nj nj

(3 rows affected)

Q1) I want to delete the second row with is ---- ---- -----.
Can delete 2nd row using following
Code:
sed '2d' FileA >FileB

but incase the second record is not ---- ---- -----.
then data will get deleted how to implement this logic to check ---- ---- ----- before deleting.



Q2) the last row will be (x rows affected)
i can implement this using

Code:
sed '$d' FileA > FileB

but in case last record is not (x rows affected)
data gets deleted how can i handle this.
I want to check before deleting.


Appreciate help.
# 2  
Old 05-01-2009
don't delete as SECOND and LAST. Delete as 'beginning "with ----" ' and 'containing "rows containing)" '.
# 3  
Old 05-01-2009
try this

Code:
sed -e '/^--.*$/d' -e '/^(.*rows affected)$/d' fileA >fileB



cheers,
Devaraj Takhellambam
# 4  
Old 05-01-2009
Quote:
Originally Posted by devtakh
try this

Code:
sed -e '/^--.*$/d' -e '/^(.*rows affected)$/d' fileA >fileB



cheers,
Devaraj Takhellambam

Thank you Devaraj Takhellambam and vgersh99
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

deleting text records with sed (sed paragraphs)

Hi all, First off, Thank you all for the knowledge I have gleaned from this site! Deleting Records from a text file... sed paragraphs The following code works nearly perfect, however each time it is run on the log file it adds a newline at the head of the file, run it 5 times, it'll have 5... (1 Reply)
Discussion started by: Festus Hagen
1 Replies

2. Shell Programming and Scripting

Need logic for check automated Job work in awk or SED.

I have a Java program which will automatically trigger some scheduled job to update Db or some other work. I am tracking the jobs with log messages and finding out it is properly run or not. I want to write a script to capture it correctly on time. Say Job1 is running on 15, 30, and 45 every... (5 Replies)
Discussion started by: senthilkumar_ak
5 Replies
Login or Register to Ask a Question