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
need help cutting consecutive lines with sed or awk raghin Shell Programming and Scripting 2 06-04-2008 04:59 AM
grab next consecutive line or lines wisher115 Shell Programming and Scripting 1 12-07-2006 08:01 AM
need help appending lines/combining lines within a file... mr_manny Shell Programming and Scripting 2 01-06-2006 06:45 PM
Appending line/lines with sed nir_s Shell Programming and Scripting 28 07-24-2005 02:36 AM
Cutting n consecutive lines from a file... Vishnu UNIX for Dummies Questions & Answers 2 10-18-2002 10:49 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 07-11-2004
pondlife pondlife is offline
Registered User
  
 

Join Date: May 2004
Location: UK
Posts: 85
Unhappy Appending Consecutive lines

Hi,

I have a file containing a single field on every row. What I need is to append one on to the end of another, e.g.

The input file looks like this:

nnnnn
mmmmmm

nnnnn
mmmmmm

I need it to look like this:

nnnnn mmmmmm

nnnnn mmmmmm

Any ideas would be much appreciated, Thanks
  #2 (permalink)  
Old 07-12-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Try...

paste -d" " - - < infile > outfile

Or...

awk -v RS="" '{$1=$1};1' infile > outfile
  #3 (permalink)  
Old 07-14-2004
pondlife pondlife is offline
Registered User
  
 

Join Date: May 2004
Location: UK
Posts: 85
Hi Ygor,

Thanks for this. The paste command is the one that works for me. The awk script outputs just one consecutive line but this might be how I've created my file...

Cheers, pondlife.
  #4 (permalink)  
Old 07-15-2004
bcheaib bcheaib is offline
Registered User
  
 

Join Date: Jul 2004
Location: Beirut
Posts: 25
Red face

Dear Ygor;

Can you please explain in some words the syntax you wrote??
specially the past command

i like your ways guys
  #5 (permalink)  
Old 07-15-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
For the AWK command.....

If my input file contains....
Code:
nnnnnnnn
mmmmmmmmmmmmmm

nnnnnnnn
mmmmmmmmmmmmmm

nnnnnnnn
mmmmmmmmmmmmmm
I use the command
Code:
awk 'BEGIN{RS="\n\n"} {printf("%s %s\n", $1, $2)}' infile > outfile
to produce the output
Code:
nnnnnnnn mmmmmmmmmmmmmm
nnnnnnnn mmmmmmmmmmmmmm
nnnnnnnn mmmmmmmmmmmmmm
Cheers
ZB
  #6 (permalink)  
Old 07-15-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
zazzybob,

Does this work on your file?

awk -v RS="" '{$1=$1};1' infile
  #7 (permalink)  
Old 07-15-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Quote:
Originally posted by Ygor
zazzybob,

Does this work on your file?

awk -v RS="" '{$1=$1};1' infile
Yes it does - I'm not too sure how the OP has his file constructed - I constructed mine exactly as per his original post.
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 10:54 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