add a line after a pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting add a line after a pattern
# 1  
Old 05-07-2007
add a line after a pattern

Hi

I have s startup script with start) and stop) clauses.

I am looking for a sed syntax in another shell script to add a line after start) and a line after stop in the startup file.

Any idea please??

thx
# 2  
Old 05-07-2007
Quote:
Originally Posted by melanie_pfefer
Hi

I have s startup script with start) and stop) clauses.

I am looking for a sed syntax in another shell script to add a line after start) and a line after stop in the startup file.

I'd use awk, not sed, e.g.:

Code:
awk -v startline="line to add after start)" -v stopline="line to add after stop)" 
/start)/ { print; print startline; next }
/stop)/ { print; print stopline; next }
            { print }'

# 3  
Old 05-07-2007
With sed :
Code:
# add.sed
/start)/a\
line 1 added after start\
line 2 added after start
/stop)/a\
line added after stop

Code:
sed -f add.sed infile

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

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

3. Shell Programming and Scripting

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 <dbrollbacksegs <oa_var="s_db_rollback_segs">NOROLLBACK</dbrollbacksegs> when ever i find the following line <dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool> I have succedded till adding a new line... (1 Reply)
Discussion started by: smarlaku
1 Replies

4. Shell Programming and Scripting

Insert new pattern in newline after the nth occurrence of a line pattern - Bash in Ubuntu 12.04

Hi, I am getting crazy after days on looking at it: Bash in Ubuntu 12.04.1 I want to do this: pattern="system /path1/file1 file1" new_pattern=" data /path2/file2 file2" file to edit: data.db - I need to search in the file data.db for the nth occurrence of pattern - pattern must... (14 Replies)
Discussion started by: Phil3759
14 Replies

5. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

6. Shell Programming and Scripting

Search a pattern and add new line below

Hi, I have 2 files like below. File A: apple mango File B: start abc def apple ghi end start cba fed (4 Replies)
Discussion started by: jayadanabalan
4 Replies

7. Shell Programming and Scripting

How to search pattern and add that pattern in next line

Hi All, I am new to shell scripting and need help in scripting using CSH. Here is what I am trying to so, 1. Search a specific string e.g. "task" from "task (input1, out1)". 2. Extract the arguements "input1" and "out1" 3. Add them in separate lines below. eg. "int input1" , " integer out1" ... (7 Replies)
Discussion started by: deshiashish
7 Replies

8. Shell Programming and Scripting

find pattern, delete line with pattern and line above and line below

I have a file that will sometimes contain a pattern. The pattern is this: FRM CHK 0000 I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (4 Replies)
Discussion started by: nickg
4 Replies

9. UNIX for Dummies Questions & Answers

find pattern delete line with pattern and line above and line below

I have a file that will sometimes contain a pattern. The pattern is this: W/D FRM CHK 00 I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (1 Reply)
Discussion started by: nickg
1 Replies

10. UNIX for Dummies Questions & Answers

Add a line after last occurnace of a pattern.

Hey guys, I was looking for a simple script to add a line after a pattern. Only that the pattern can occur tons of times in a file. I have to add a line once after the "last" occurance of the pattern. eg. file xyz agwer asdf234 pattern... 212541234 df pattern . . . . last... (2 Replies)
Discussion started by: n_rajitr
2 Replies
Login or Register to Ask a Question