sed adding a new line not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed adding a new line not working
# 1  
Old 02-19-2013
Oracle sed adding a new line not working

Code:
sed '/patternstring/ a\ new line string' file1

The above code is not working even with the i option....
it shows sed grambled if '\' after new line string is not being used....after using no changes it is displaying..Pls help

Last edited by Franklin52; 02-19-2013 at 04:00 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 02-19-2013
Use code tags for code and data sample.

Try

Code:
sed 's/patternstring/\n new line string/' file

This User Gave Thanks to pamu For This Post:
# 3  
Old 02-19-2013
it is still not workingSmilieSmilieSmilie
# 4  
Old 02-19-2013
Quote:
Originally Posted by bhavanabahety
sed '/patternstring/ a\ new line string' file1
Try placing what follows the backslash on the next line.

Quote:
Originally Posted by bhavanabahety
it is still not workingSmilieSmilieSmilie
That is absolutely useless feedback. Tell us which sed implementation and operating system you're using. Show us the command you ran. Show us the data that's the input for the command. Show us the incorrect output that is being generated. And, finally, show us the correct output that you desire.


Quote:
Originally Posted by pamu
Code:
sed 's/patternstring/\n new line string/' file

A lot of sed implementations (and the POSIX standard) do not support the \n newline escape sequence in replacement text. The portable approach is to use a backslash followed by a literal newline.

Regards,
Alister
# 5  
Old 02-19-2013
The file which is used is
Code:
/abc/apps/cobbbbbb/apps/abadv/binder/axyz.bnd
/abc/apps/cobbbbbb/apps/abbrio/binder/na6115.bnd
/abc/apps/cobbbbbb/apps/abbrio/binder/kc22.bnd
/abc/apps/cobbbbbb/apps/abbrio/binder/tr4823.bnd
/abc/apps/cobbbbbb/apps/abcmp/binder/cpc0105.bnd

The commads which I ran through are:
Code:
sed '/axyz.bnd/ a\grant permissions given  ' file1

and
Code:
sed '/axyz.bnd/  i\grant permissions given  ' file1

..
If above commands are given it is showing an error so i added a '\'
Code:
sed '/axyz.bnd/  i\grant permissions given \ ' file1

..This time no error but no output..Pls help

Last edited by Franklin52; 02-19-2013 at 07:43 AM.. Reason: Please use code tags for data and code samples
# 6  
Old 02-19-2013
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Adding a new line after a specific line with sed

Hi All, My requirement is to add a specific line in a file after a certain line that contains 'setenv' the existing code is like setenv SEQFILES "/ConvWrk/inteng03/alltars/bnymais1" LIBDEF scope='JOB' type='PGM' dataset='SUNAR.PJ90000P.JOBLIB'... (5 Replies)
Discussion started by: gotamp
5 Replies

2. Shell Programming and Scripting

sed adding a new line not working

The file which is used is /abc/apps/cobbbbbb/apps/abadv/binder/axyz.bnd /abc/apps/cobbbbbb/apps/abbrio/binder/na6115.bnd /abc/apps/cobbbbbb/apps/abbrio/binder/kc22.bnd /abc/apps/cobbbbbb/apps/abbrio/binder/tr4823.bnd /abc/apps/cobbbbbb/apps/abcmp/binder/cpc0105.bnd The commads which I ran... (3 Replies)
Discussion started by: bhavanabahety
3 Replies

3. UNIX for Dummies Questions & Answers

Sed: Adding new line after matching pattern

Hi I just wanted to add a new line after every matching pattern: The method doing this doesn't matter, however, I have been using sed and this is what I tried doing, knowing that I am a bit off: sed 'Wf a\'/n'/g' Basically, I want to add a new line after occurrence of Wf. After the line Wf... (5 Replies)
Discussion started by: MIA651
5 Replies

4. Shell Programming and Scripting

help with sed adding line to end of file

sed '$a\ hello' books hi i am trying to use sed to append hello to the end of the file books, but for some reason i can't get it work. It keeps sayin command garbled. Anyone know what I'm doing wrong. this is in a ksh script as well. (3 Replies)
Discussion started by: bjhum33
3 Replies

5. Shell Programming and Scripting

sed adding a blank line

I use the following as part of a script to correct for a faulty hostname file. # get the domain name read -r thehostname < /etc/hostname dom="$(echo $thehostname | cut -d'.' -f2)" numchar=${#dom} if then echo "It appears as though the hostname is not correctly set." echo "Hostname has... (5 Replies)
Discussion started by: bugeye
5 Replies

6. Shell Programming and Scripting

SED - adding blank line after each Range Match

the following range matching works great but i wish to add a blank line after each range result set... which i've tried and researched to no avail MY INPUT DATA: CURRENT CODE I'M USING: sed -n '/*$/,/;/p' $INPUT_FILE RESULTS I'M GETTING: RESULT I looking to... (5 Replies)
Discussion started by: danmauer
5 Replies

7. Shell Programming and Scripting

Need help in sed: adding a line after each search block

Hi friends, I have written script that will search & display the block of sql statement. Since there are many blocks of sql statement i am finding it difficult to distinguish between them. The below is the sed command & its result exec sql abc abc abc... (2 Replies)
Discussion started by: frozensmilz
2 Replies

8. Shell Programming and Scripting

SED - adding a new line after pattern

Hi, In files, I have a field Date Of Birth (DOB). After that line I need to add Date of Joining (DOJ) DOB:19-Apr-1981 needs to become DOB:19-Apr-1981 DOJ:20-Jun-2005 What can be a sed/perl line that can do it for me. Please note that DOB/DOJ I have in variables I am doing in a... (6 Replies)
Discussion started by: eagercyber
6 Replies

9. UNIX for Dummies Questions & Answers

sed - adding new line

I want to use sed to look for spaces in text and when find one move the next word to the next line. I used: sed 's/ /\n/g' out > new However when there is more than one space between two words it adds more lines between them. And I just want the words to be one under another. How can I... (2 Replies)
Discussion started by: sovixi
2 Replies

10. Solaris

adding a new line using sed command

I need to find text "A" and replace it with A B. The issue is that I need a new line between A and B. \n does not do the work. Any help would be much appreciated. Thanks, (2 Replies)
Discussion started by: ivesia
2 Replies
Login or Register to Ask a Question