Inserting a carriage rtn in a sed cmd


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inserting a carriage rtn in a sed cmd
# 1  
Old 07-06-2006
Inserting a carriage rtn in a sed cmd

I suppose this is a silly newbie Q, but I have a set of text I am inserting into a file using a sed cmd and before I insert, I want to ask the sed operation to move to add a carriage return first, and then place my new line.

Is there scope within the sed command to do this - i have tried "\n" as follows with obivous run-time errors:-

$cat fileToEdit | sed -e $lineToEnterNewText's/$oldline \n $newText/' > fileToEdit

Thanks
# 2  
Old 07-07-2006
$ cat fileToEdit | sed -e "$lineToEnterNewText"' s/^\(.*\)$/\1\
'"$newText"'/' > fileToEdit
# 3  
Old 07-07-2006
Some versions of sed recognize escape sequences:
Code:
echo tvparty |sed 's/\(tv\)\(party\)/\1\n\2/g'

For example, I'm using GNU sed...
# 4  
Old 07-07-2006
In sed in match part of s/// escape sequence (\n) can be used, in replace part - only newline (as I've shown above)
# 5  
Old 07-07-2006
I may have misunderstood, but I think you are correct - sed has a hard time matching newline, but it can insert a newline (depending on version, as I said before.) However, on second review, it looks like he may have wanted to add newline to the start of a line...
If we can remove sed, why not ' printf "\n$string" '?

If I didn't get it right this time, mea culpa.
# 6  
Old 07-07-2006
Quote:
Originally Posted by macosta
to add newline to the start of a line
ha? then we'll get 2 lines Smilie
# 7  
Old 07-14-2006
Strange, neither of the ways work on my sed version..? although it does say in the info page - version 3.02 of GNU Sed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create Carriage Return using SED

I am hoping someone can help me with a solution to this problem using SED. My issue is actually two-fold. First, I have an order file that is sent to us from another system, however, there has been a change in current processes that requires a carriage return added to the end of each order. The... (5 Replies)
Discussion started by: chino_1
5 Replies

2. Shell Programming and Scripting

Why sed command deletes last line in a file if no carriage return?

Hi I am using sed command to make SCORE=somevalue to SCORE=blank in a file. Please see the attached lastline.txt file. After executing the below command on the file, it removes the last line. cat lastline.txt | sed 's/SCORE=.*$/SCORE=/g' > newfile.txt Why does sed command remove the... (3 Replies)
Discussion started by: ashok.k
3 Replies

3. Emergency UNIX and Linux Support

Adding carriage returns to file using sed/awk

Hello, I need help adding carriage returns at specific intervals (say 692 characters) to a text file that's one continous string. I'm working in AIX5.3. Any quick help is appreciated. Thanks! (2 Replies)
Discussion started by: bd_joy
2 Replies

4. UNIX for Dummies Questions & Answers

sed cmd

write the sed command for swapping the first and 2nd (fields)words in the following file input file cse1 rama 1223 cse2 raju 2453 cse3 sita 3523 i tried with this $sed 's/ \(*\)/ \(*\)/ \2,\1' myfile1 but not getting th required... (4 Replies)
Discussion started by: sankar_vitam
4 Replies

5. UNIX for Dummies Questions & Answers

use sed to replace whitespace with a carriage return

Greetings I need to replace "whitespace" in a file with the newline character aka carriage return My command is either wrong or not interpreted properly by me shell sed s/" "/\\n" "/g nets > nets1 or sed s/" "/\n" "/g nets > nets1 nets (input file) 13MHZ_IN... (4 Replies)
Discussion started by: awk_sed_hello
4 Replies

6. Shell Programming and Scripting

Delete carriage return in SED

Hi everybody! I'm working in one script with sed, I have file with the next content: <voms.db.type value="changeme"/> <voms.db.host value="changeme"/> <voms.admin.smtp.host value="changeme"/> <voms.mysql.admin.password value="changeme"/> <glite.installer.verbose value="true"/> ... (3 Replies)
Discussion started by: juedsivi
3 Replies

7. Shell Programming and Scripting

removing thousand of carriage returns using sed

I need to replace thousands of carriage returns/line breaks in a large xml file and with spaces. I hope to do so with a script, called, for example, "removeCRs." I would invoke this at the command line as ml5003$ sed -f /Users/ml5003/removeCRs oldFile > newFile The script, I presume, would... (4 Replies)
Discussion started by: ml5003
4 Replies

8. Shell Programming and Scripting

Removing carriage returns with sed

How do we delete all carriage returns after a particular string using sed inside a K Shell? e.g. I have a text file named file1 below: $ more file1 Group#=1 User=A Role=a1 Group#=2 User=B Role=a1 Role=b1 Group#=3 User=C Role=b1 I want the carriage returns to be delete on the... (12 Replies)
Discussion started by: stevefox
12 Replies

9. Shell Programming and Scripting

How to delete carriage return in SED

Could someone tell me how to do the below without opening the file? (eg in sed or awk) I have a file with the contenst below: $ more file1.txt 10 AAA; 200 BBB; 3 CCC; I want to delete the carriage return of one line above the line which has ";" at the end to get the... (3 Replies)
Discussion started by: stevefox
3 Replies

10. Shell Programming and Scripting

sed removing carriage return and newline

Hi, I'm not very familiar with unix shell. I want to replace the combination of two carriage returns and one newline with one carriage return and one newline. I think the best way to do this is to use sed. I tried something like this: sed -e "s#\#\#g" file.txt but it doesn't work. Thanx... (2 Replies)
Discussion started by: mored
2 Replies
Login or Register to Ask a Question