The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
add carriage return at end of file HAA Shell Programming and Scripting 2 11-20-2007 10:58 AM
Carriage Return at end of file bd_joy Shell Programming and Scripting 14 10-20-2006 01:20 PM
How to delete carriage return in SED stevefox Shell Programming and Scripting 3 12-23-2005 05:03 AM
Dont want carriage return videsh77 Shell Programming and Scripting 3 12-16-2004 08:26 PM
Capture carriage return. gio123bg Shell Programming and Scripting 4 12-15-2003 09:21 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-09-2008
Registered User
 

Join Date: Oct 2008
Posts: 2
Post 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
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-09-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,293
Wink 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
Reply With Quote
  #3 (permalink)  
Old 10-09-2008
Moderator
 

Join Date: Feb 2007
Posts: 3,549
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 01:24 PM.. Reason: adding comments
Reply With Quote
  #4 (permalink)  
Old 10-09-2008
Registered User
 

Join Date: Oct 2008
Posts: 2
Quote:
Originally Posted by joeyg View Post
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 help 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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
None

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 08:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66