To add a new line with specific text after the pattern is found using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To add a new line with specific text after the pattern is found using sed
# 1  
Old 01-11-2013
To add a new line with specific text after the pattern is found using sed

hi guys,

im trying to add the following line in my xml file
Code:
<dbrollbacksegs <oa_var="s_db_rollback_segs">NOROLLBACK</dbrollbacksegs>

when ever i find the following line
Code:
<dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool>

I have succedded till adding a new line after the above searched pattern but not able to insert my specifc part (NOROLLBACK)

Code:
users/oracle> cat  file
    <dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool>
/users/oracle > sed 's/dbsharedpool>/&\n/g' file
         <dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool>

/users/oracle >

But my Output should be something like this
Code:
/users/oracle > sed 's/dbsharedpool>/&\n/g' file
         <dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool>
         <oa_var="s_db_rollback_segs">NOROLLBACK</dbrollbacksegs>
/users/oracle >

Pls help
# 2  
Old 01-11-2013
Code:
# cat file
<dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool>
<ABCD>
</ABCD>
<EFGH>
</EFGH>

Code:
#  sed '/<\/dbsharedpool>/ a\ <dbrollbacksegs <oa_var="s_db_rollback_segs">NOROLLBACK</dbrollbacksegs>' file
<dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool>
 <dbrollbacksegs <oa_var="s_db_rollback_segs">NOROLLBACK</dbrollbacksegs>
<ABCD>
</ABCD>
<EFGH>
</EFGH>

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 with sed to combine lines and remove specific odd # pattern from line

In the awk piped to sed below I am trying to format file by removing the odd xxxx_digits and whitespace after, then move the even xxxx_digit to the line above it and add a space between them. There may be multiple lines in file but they are in the same format. The Filename_ID line is the last line... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. UNIX for Beginners Questions & Answers

Modify text file if found multiple pattern match for every line.

Looking for help, i have input file like below and want to modify to expected output, if can without create additional file, hope can direct modify it. have 2 thing need do. 1st is adding a word (testplan generation off) after ! ! IPG: Tue Aug 07 14:31:17 2018 2nd is adding... (16 Replies)
Discussion started by: kttan
16 Replies

3. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

4. Shell Programming and Scripting

Append text on particular line after pattern found

hi, i have /etc/inittab, I want to add another line after that when i find a pattern "l6:6:wait:/etc/rc.d/rc 6". original l6:6:wait:/etc/rc.d/rc 6 after-change l6:6:wait:/etc/rc.d/rc 6 /sbin/if-pp-to-cng (3 Replies)
Discussion started by: learnbash
3 Replies

5. Shell Programming and Scripting

If first pattern is found, look for second pattern. If second pattern not found, delete line

I had a spot of trouble coming up with a title, hopefully you'll understand once you read my problem... :) I have the output of an ldapsearch that looks like this: dn: cn=sam,ou=company,o=com uidNumber: 7174 gidNumber: 49563 homeDirectory: /home/sam loginshell: /bin/bash uid: sam... (2 Replies)
Discussion started by: samgoober
2 Replies

6. Shell Programming and Scripting

Displaying text till pattern match found in a line

Hi All, From the below line if we want to display all the text till found pattern dot/. I was trying with the below code but couldn't able to print text before the pattern. it display texts which is found after pattern. awk '/assed/{print;getline;print}' file_name | sed 's/^*. *//' input... (4 Replies)
Discussion started by: Optimus81
4 Replies

7. Shell Programming and Scripting

extract specific line if the search pattern is found

Hi, I need to extract <APPNUMBER> tag alone, if the <college> haas IIT Chennai value. college tag value will have spaces embedded. Those spaces should not be suppresses. My Source file <Record><sno>1</sno><empid>E0001</empid><name>Rejsh suderam</name><college>IIT ... (3 Replies)
Discussion started by: Sekar1
3 Replies

8. Shell Programming and Scripting

sed: Find start of pattern and extract text to end of line, including the pattern

This is my first post, please be nice. I have tried to google and read different tutorials. The task at hand is: Input file input.txt (example) abc123defhij-E-1234jslo 456ujs-W-abXjklp From this file the task is to grep the -E- and -W- strings that are unique and write a new file... (5 Replies)
Discussion started by: TestTomas
5 Replies

9. Shell Programming and Scripting

Sed: add text if pattern not found

Hello, I would like to add the line TIMEZONE="CET" if the pattern TIMEZONE is not found between the range <JOB and JOB> : Example: Src file: <!DOCTYPE DEFTABLE SYSTEM "deftable.dtd"> <DEFTABLE > <JOB TASKTYPE="Job" TIMEFROM="0030" TIMEZONE="CET" </JOB> <JOB... (5 Replies)
Discussion started by: mutunzi
5 Replies

10. Shell Programming and Scripting

change line found by pattern using sed

I want to change a line like CPM_THRESHOLD 0.8 // to a new value using sed I am trying sed -i "s/CPM_THRESHOLD/CPM_THRESHOLD\t$COH\t\t\/\//" $INPUT_4 but how can i substitute the whole line begining with CPM_THRESHOLD and substitute it? (2 Replies)
Discussion started by: larne
2 Replies
Login or Register to Ask a Question