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 11:58 AM
Carriage Return at end of file bd_joy Shell Programming and Scripting 14 10-20-2006 02:20 PM
How to delete carriage return in SED stevefox Shell Programming and Scripting 3 12-23-2005 06:03 AM
Dont want carriage return videsh77 Shell Programming and Scripting 3 12-16-2004 09:26 PM
Capture carriage return. gio123bg Shell Programming and Scripting 4 12-15-2003 10:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-09-2008
juedsivi juedsivi is offline
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
  #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,311
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
  #3 (permalink)  
Old 10-09-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,327
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 (permalink)  
Old 10-09-2008
juedsivi juedsivi is offline
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:35 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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