Delete carriage return in SED


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete carriage return in SED
# 1  
Old 10-09-2008
Java 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"/>

I want the output file is as follows

<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"/>


Thanks for your help
# 2  
Old 10-09-2008
Hammer & Screwdriver Here is one approach

Code:
> cat file3
<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"/>
> sed "s/>/>~/g" file3 | tr -d "[ ][\n]" | tr "~" "\n"
<voms.db.typevalue="changeme"/>
<voms.db.hostvalue="changeme"/>
<voms.admin.smtp.hostvalue="changeme"/>
<voms.mysql.admin.passwordvalue="changeme"/>
<glite.installer.verbosevalue="true"/>
>

Explained...
substitute > with >~ so can easily find end-of-lines
delete space and new-line characters
(note, the sample I copied/pasted had extra spaces after data in some lines)
then substitute new-lines for the ~ I used as marker in first step

Expect someone to offer an easier solution, but this is one approach
# 3  
Old 10-09-2008
Another one, if the last character of the line isn't a ">", add the next line into the contents of the pattern space and delete the newline character:

Code:
sed -n '/[^>]/$/N;s/\n//p' file

With awk, if the last character of the line isn't a ">" print the line without a newline:

Code:
awk '!/>$/{printf("%s",$0);next}1' file

Regards

Last edited by Franklin52; 10-09-2008 at 02:24 PM.. Reason: adding comments
# 4  
Old 10-09-2008
Quote:
Originally Posted by joeyg
Code:
> cat file3
<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"/>
> sed "s/>/>~/g" file3 | tr -d "[ ][\n]" | tr "~" "\n"
<voms.db.typevalue="changeme"/>
<voms.db.hostvalue="changeme"/>
<voms.admin.smtp.hostvalue="changeme"/>
<voms.mysql.admin.passwordvalue="changeme"/>
<glite.installer.verbosevalue="true"/>
>

Explained...
substitute > with >~ so can easily find end-of-lines
delete space and new-line characters
(note, the sample I copied/pasted had extra spaces after data in some lines)
then substitute new-lines for the ~ I used as marker in first step

Expect someone to offer an easier solution, but this is one approach
Thank you for your helpSmilie joeyg
the spaces are necesary, because after, I need capturing lines for show with Dialog, and the delimiter is value="changeme"... I change should be replaced by the user...

<voms.db.type value="changeme"/>
<voms.db.host value="changeme"/>

Thank You for your help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Help to delete carriage return and new line in csv file

Hi All, I have a problem loading the data from a csv file As you see below in the Input ,For the Data starting with " there are 2 lines, which i want to make them into single without changing the format of that data. You can see the desired output below: While i try to open the csv file and... (4 Replies)
Discussion started by: mlavanya
4 Replies

2. Shell Programming and Scripting

Substitute \n with carriage return

Hello all, I've a flat file in the following format: AB\001\CDED\001\ABC\001\nEG\001\HIJF\001\EFG\001\nHI\003\HIUL\003\HIJ\003 And I want to substitute \n with the carriage return. Any help is appreciated! Regards, - Seth (8 Replies)
Discussion started by: sethmj
8 Replies

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

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

5. UNIX for Dummies Questions & Answers

carriage return and linefeed

hi can anyone please tell me the difference between carriage return, linefeed and newline ? (2 Replies)
Discussion started by: streetfi8er
2 Replies

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

7. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

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

9. Shell Programming and Scripting

Dont want carriage return

I have observed with print & echo, they produce carriage return <CR> or newline, after they display string next to them. Is there anyway to avoide these <CR> after the intended string is displayed? (3 Replies)
Discussion started by: videsh77
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