Delete a line and the next line containing a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete a line and the next line containing a string
# 8  
Old 12-13-2010
The space in between /.../ in sed are for pattern matching. So whatever pattern your trying to match place it in between the forward slashes..like below
Code:
sed '/<Opt>-L$ORACLE_HOME\/lib/.....' inputfile

Since there is already a forward slash in your pattern string (<Opt>-L$ORACLE_HOME/lib) you need that to be escaped.
This User Gave Thanks to michaelrozar17 For This Post:
# 9  
Old 12-13-2010
yeah, but in my case, the pattern after,

<Opt>-L$ORACLE_HOME/lib32 **********
</Opt>

here ******** varies file to file!

please help out!
# 10  
Old 12-13-2010
Code:
perl -i -pe 'undef $/; s/<(Opt)>-L\$ORACLE_HOME.*?<\/\1>([^\n]*\n){2}//s; ' infile


Last edited by k_manimuthu; 12-13-2010 at 07:10 AM.. Reason: Update the code
This User Gave Thanks to k_manimuthu For This Post:
# 11  
Old 12-13-2010
But this doesnt work!!

anything with sed will be of great help! thanks.
# 12  
Old 12-13-2010
I update my previous post. Try the updated code.
This User Gave Thanks to k_manimuthu For This Post:
# 13  
Old 12-13-2010
Quote:
Originally Posted by pradebban
yeah, but in my case, the pattern after,

<Opt>-L$ORACLE_HOME/lib32 **********
</Opt>

here ******** varies file to file!

please help out!
Can you elaborate on your requirement..? If given like /-L$ORACLE_HOME\/lib32/ -- this prints all the lines containing the pattern and it could be of any line as below..
Code:
-L$ORACLE_HOME/lib32 some text here
some text here -L$ORACLE_HOME/lib32
some-L$ORACLE_HOME/lib32text here
some text here -L$ORACLE_HOME/lib32 some more text

Else if you want to match something more precisely then post your pattern and the sample lines of input file..
# 14  
Old 12-13-2010
sorry Smilie

-L$ORACLE_HOME/lib32 some text here

this is it!. thanks

please help out :|

---------- Post updated at 05:48 PM ---------- Previous update was at 04:53 PM ----------

Any inputs would be of great help!

Last edited by pradebban; 12-13-2010 at 08:14 AM..
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 find string and delete before just in line?

Hello, When my lines contain question mark, I use below command to delete the portion of the matching line coming after question mark: sed 's/?.*//' SampleFile SampleFile: helloworldfirstline?mdksmyymsss hellosecondlineworld?mdksmkkmsss thirdhelloworld?mdksmccmsss Output:... (2 Replies)
Discussion started by: baris35
2 Replies

2. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

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

4. Shell Programming and Scripting

Delete the last line if match the string

Hi, How to delete the last line if is match the below string else no action... String checking "END OF FILE. ROW COUNT: " 9f680174-cb87-4f71-887a-93b6f62fa5aa|20077337254|2 9f680174-cb87-4f71-887a-93b6f62fa5aa|20077337254|0 229f680174-cb87-4f71-887a-93b6f62fa5aa|20077337254|3 END OF... (2 Replies)
Discussion started by: bmk
2 Replies

5. Shell Programming and Scripting

bash: delete a string from last line

I am using a while loop to read a file and i have to delete a string from the last line. Here is the code so far: 1. Read line by line from file new.html using while loop and store in a variable data 2.Now, need to replace '||chr( from last line in data I am able to replace that character from... (12 Replies)
Discussion started by: Chella15
12 Replies

6. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

7. Shell Programming and Scripting

Search for a line, delete a string in it

let me start out by saying i have ZERO exp with any kind of scripting, so sorry if this is really basic stuff..... For example, I need to have a script that will search a file and find this line in the file: *.cat;dog;kennel;house;barn;horse;hay;coat hat and remove the "coat" from the... (12 Replies)
Discussion started by: skunky
12 Replies

8. Shell Programming and Scripting

search string and delete the line

Hi All, I have a file from Mainframe which has one of the lines with so many words... i tried to fold, format to 80 chararcter.. stil did not work. So i have decided to search for a string in that line Ex.FLIGHT PLAN and once if it is found i want to delete the entire line. Please help... (2 Replies)
Discussion started by: digitalrg
2 Replies

9. Shell Programming and Scripting

delete a string from line

hi i have a file contains data session terminated Line timeout: 120 Change state START->SIGNON_REPLY, RC=0 Change state SIGNON_REPLY->SIGNON, RC=0 i need to remove "Change state" and write to the same file please help thanks Satya (3 Replies)
Discussion started by: Satyak
3 Replies

10. Shell Programming and Scripting

Delete a Line with a string X

Hi guys, I am new here. I have done many scripts in VisualBasic and batch. Now going to *inux and learning bash and perl, quite amazing commands I find in linux, like sed, grep, awk and so on... the task is simple, find a string in folders and remove the line where that string exists. I can... (3 Replies)
Discussion started by: 4scriptmoni
3 Replies
Login or Register to Ask a Question