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
TO break a line aajan Shell Programming and Scripting 7 08-28-2007 04:12 AM
Insert line break in vi's command mode Skogsmulle UNIX for Dummies Questions & Answers 3 07-06-2007 10:47 AM
Replacing characters in file with line break johnemb Shell Programming and Scripting 10 04-26-2007 07:38 AM
Sed Help (Using expression - line break) Janus Shell Programming and Scripting 2 02-16-2007 08:50 PM
Trim whitespace and add line break moose1 Shell Programming and Scripting 7 01-22-2007 01:53 PM

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 02-06-2007
Rock Rock is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 23
Remove Line Break

Dear all,


Please advise what approach can remove all line break from a text file?
e.g.
Source file:
A
B
C

Target file:
A, B, C


Thanks,
Rock
  #2 (permalink)  
Old 02-06-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
this had been answered many times

please search the forums


Code:
awk 'BEGIN{}{printf "%d, ", NR}END{printf "\n"}' filename
  #3 (permalink)  
Old 02-06-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
A similar result can be achieved with
Code:
paste -s -d',' tmpfile | sed 's/,/, /g'
Cheers
ZB
  #4 (permalink)  
Old 02-06-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,420
Using awk again :
Code:
awk '{printf("%s", $0 (NR==1 ? "" : ","))}' filename

Jean-Pierre.
  #5 (permalink)  
Old 02-06-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
sed -n -e ":a" -e "$ s/\n/,/gp;N;b a" file
or
Code:
var=$( tr '\n' '-' <file )
var=${var%-}
  #6 (permalink)  
Old 02-06-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,860
Quote:
Originally Posted by Rock
Please advise what approach can remove all line break from a text file?
e.g.
Source file:
A
B
C

Target file:
A, B, C
[...]
Code:
awk '$1=$1' OFS=", " RS= infile
Use nawk on Solaris.
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 12:34 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