Visit Our UNIX and Linux User Community


sed - how to replace a line with a new line?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed - how to replace a line with a new line?
# 1  
Old 11-04-2009
sed - how to replace a line with a new line?

HI Gurus - Need some help with sed. I have been struggling for last few hours to get this working but in vain. Here is the problem:

I have a file as shown below:
#!/usr/bin/ksh
. /db2bkup/dba/standard/db2td2/instance/DB2TD2.sh
. /db2bkup/dba/standard/db2td2/bin/db2td2.td2.variables
#VERSION=1.0.0.1
export SEND_PAGE_ONCALL="no"
export SEND_INFO_ONCALL="no"
export SENDUSRALM="no"
export SENDEMAIL="yes"
. ~$DB2INSTANCE/sqllib/db2profile
export compressbkup="compress" #to compress use the following syntax compressbkup="compress"
##export backupdir='/db2bkup/TD2/online/data1,/db2bkup/TD2/online/data2,/db2bkup/TD2/online/data3,/db2bkup/TD2/online/data4'
export backupdir='/db2/TD2/bkup01/online/data1,/db2/TD2/bkup01/online/data2,/db2/TD2/bkup01/online/data3,/db2/TD2/bkup01/online/data4'
#to use multiple directories. Ex. export backupdir='/db2bkup01/sample1,/db2bkup01/sample2'
##$DBALIB/config/backup.online

The line is question is line 12 (need not be line 12 always; just happens to be the one in the above script) and is shown below: (Note there is a similar line 11 but with comments. I want to leave this line 11 as it is).

export backupdir='/db2/TD2/bkup01/online/data1,/db2/TD2/bkup01/online/data2,/db2/TD2/bkup01/online/data3,/db2/TD2/bkup01/online/data4'

I want to replace this line with a memory variable (say $newfilepath).
How do I search specifically for this line in the file and replace it using sed or for that matter any other command ?

Please help. Thank you for your time.
# 2  
Old 11-04-2009
Thank you thegeek.
This will work only in the present case. But, my files might have anything from

export backupdir='/db2/TD2/bkup01/online/data1'
export backupdir='/db2/TD2/bkup01/online/data1,/db2/TD2/bkup01/online/data2'
backupdir='/db2/TD2/bkup01/online/data1,/db2/TD2/bkup01/online/data2,,/db2/TD2/bkup01/online/data3'

pl help.
Thanks.
# 3  
Old 11-04-2009
So !!!!




If you want to replace all the three lines, then use the common part in the find place, that is in the first part of s@@.

Got it ?!

Previous Thread | Next Thread
Test Your Knowledge in Computers #741
Difficulty: Medium
The successor to FORTRAN 77 was informally known as Fortran 90.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace values in script reading line by line using sed

Hi all, Let's say I have a script calling for the two variables PA_VALUE and PB_VALUE. for pa in PA_VALUE blah blah do for pb in PB_VALUE blah blah do I have a text file with two columns of values for PA and PB. 14.5 16.7 7.8 9.5 5.6 3.6 etc etc I would like to read this... (7 Replies)
Discussion started by: crimsonengineer
7 Replies

2. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

3. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

4. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

5. Shell Programming and Scripting

Replace line with sed on OS X

So, I want to, in a script, do an in-line replacement of a line in a file. Piece of cake in Linux with GNU sed. With OSX and BSD sed, not so much. I've been Googling, but nothing is really helping... either an answer is for a use case different enough from what I want to do, or it's something... (10 Replies)
Discussion started by: jnojr
10 Replies

6. Shell Programming and Scripting

I need to know how to replace a line after a pattern match with an empty line using SED

Hi How Are you? I am doing fine! I need to go now? I will see you tomorrow! Basically I need to replace the entire line containing "doing" with a blank line: I need to the following output: Hi How Are you? I need to go now? I will see you tomorrow! Thanks in advance.... (1 Reply)
Discussion started by: sags007_99
1 Replies

7. Shell Programming and Scripting

sed to do replace on line above

Hello, I need to use sed to find a certain string and then do a replace on the line above. For example if I had the following text: AAAAAAA BBBBBBB CCCCCCC DDDDDD I would like to find CCCCCCC, but I would like the replace to be carried out on BBBBBBB. I have done some... (11 Replies)
Discussion started by: toptiger
11 Replies

8. Shell Programming and Scripting

sed to replace a line with modified line in same file

i have few lines in a file... i am reading them in a while loop so a particular line is held is $line1.. consider a modified line is held in $line2.... i want to replace $line1 with $line2 in the same file... how to do it..? i have come up till the below code sed "s/$line1/$line2/g" tmpfile.sql... (5 Replies)
Discussion started by: vivek d r
5 Replies

9. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

10. Shell Programming and Scripting

sed - Replace Line which contains the Pattern match with a new line

I need to replace the line containing "STAGE_DB" with the line "STAGE_DB $DB # database that contains the table being loaded ($workingDB)" Here $DB is passed during the runtime. How can I do this? Thanks, Kousikan (2 Replies)
Discussion started by: kousikan
2 Replies

Featured Tech Videos