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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Conditionally joining lines in vi ifermon UNIX for Dummies Questions & Answers 0 06-04-2008 06:43 AM
Joining lines from two files - please help chandra004 Shell Programming and Scripting 25 07-26-2006 11:39 PM
Joining 2 lines in a file together m223464 Shell Programming and Scripting 3 05-12-2005 08:42 AM
Joining multiple lines beilstwh Shell Programming and Scripting 4 03-02-2005 02:51 AM
Joining lines in log file bubba112557 Shell Programming and Scripting 3 05-18-2004 04:10 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 12-09-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
From man sed

Code:
       n N    Read/append the next line of input into the pattern space.
See Oreilly's Sed and Awk - 6.1 Multiline Pattern Space
Reply With Quote
Forum Sponsor
  #9  
Old 12-09-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
Quote:
Originally Posted by Sabari Nath S

for eg: sed 'N;s/\n/ /' can join pairs of lines ... but not 3 lines at a time .. I am searching for some kind of one liner like that .. not a script ..

Can anyone pls help ??
To join 3 lines try:
sed 'N;N;s/\n/ /'

4 lines? try:
sed 'N;N;N;s/\n/ /'
Reply With Quote
  #10  
Old 12-09-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Quote:
Originally Posted by Perderabo
sed 'N;N;s/\n/ /'
sed 'N;N;N;s/\n/ /'
You would need the global flag at the end of those statements. Like,

Code:
sed 'N;N;s/\n/ /g'
Reply With Quote
  #11  
Old 12-10-2005
Registered User
 

Join Date: Sep 2005
Location: Chennai
Posts: 80
A bit late

paste -d"\t\t\n" <file_name>
Reply With Quote
  #12  
Old 12-13-2005
Registered User
 

Join Date: Jul 2005
Location: Chennai
Posts: 39
Thanks all

Hi all ...

Thanks a lot for all replies ...

i got 4 solutions for to this ... and the sed one was simple .... I was new to n/N option in sed too .. thanks again to all ..
Reply With Quote
  #13  
Old 12-19-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
For future reference, the simplest way to join three lines is to use the paste command, like this...
Code:
paste -d ' ' - - - < file1
Reply With Quote
  #14  
Old 12-20-2005
Registered User
 

Join Date: Jul 2005
Location: Chennai
Posts: 39
Wow !!! I was surprised to see such a small command doing this ... well cal u give an idea as to how it works ?? what do this 3 hyphens stand for ??
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:00 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0