The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Replacing Carriage returns without loosing EOL Majiktom Shell Programming and Scripting 2 03-08-2008 07:28 AM
removing thousand of carriage returns using sed ml5003 Shell Programming and Scripting 4 06-09-2006 06:22 PM
Removing carriage returns with sed stevefox Shell Programming and Scripting 12 01-26-2006 01:02 AM
spaces and carriage returns in 'here documents' hcclnoodles Shell Programming and Scripting 0 04-11-2005 07:49 AM
Removing carriage return characters from file b1saini UNIX for Dummies Questions & Answers 3 09-10-2003 10:41 AM

Reply
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 09-15-2009
coolnfunky coolnfunky is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 2
removing carriage returns in text file

Hi

I have a text file that looks like this:
A
B
C

D
E
F

G
H
I

I want it to be reformatted to
A;B;C;
D;E;F;
G;H;I;

I want a shell script to do this. Any help is greatly appreciated.

Thanks
  #2 (permalink)  
Old 09-15-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,400
no need of script this sed oneliner will do it..
Code:
sed -ne 'H
/^$/{x
s/\n/;/g
s/;//
p
}' filename
  #3 (permalink)  
Old 09-15-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 536
Code:
$ 
$ cat f1
A
B
C

D
E
F

G
H
I

$ awk '{if (/^$/){print} else{printf("%s;",$0)}}' f1
A;B;C;
D;E;F;
G;H;I;
$ 
$
tyler_durden
  #4 (permalink)  
Old 09-16-2009
coolnfunky coolnfunky is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 2
Thanks tyler_durden and vidyadhar85 for the quick replies!!
  #5 (permalink)  
Old 09-16-2009
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,431
Another one
Code:
awk 'ORS=(NF)?";":"\n"' file
Reply

Bookmarks

Tags
programming, shell, shell programming, unix

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 12:01 AM.


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