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
Combining many lines to one using awk or any unix cmd pinnacle Shell Programming and Scripting 14 05-18-2009 07:11 PM
Sed: Combining Multiple Lines into one goldfish Shell Programming and Scripting 3 09-10-2008 03:52 PM
combining lines between 2 pattern using awk shell.scriptor Shell Programming and Scripting 3 08-26-2008 08:05 PM
help combining lines in awk blueheed Shell Programming and Scripting 2 03-23-2006 06:26 PM
need help appending lines/combining lines within a file... mr_manny Shell Programming and Scripting 2 01-06-2006 06:45 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 05-06-2009
mfavero mfavero is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 2
Combining two text lines into one

Here is the sample file:
646 STARTED Tue Dec 30 06:38:53 2008
Job DdCustXAddr_brad has been reset.
647 STARTED Tue Dec 30 06:38:54 2008
Starting Job DdCustXAddr_brad. (...)
704 STARTED Tue Dec 30 06:49:02 2008
Job DdCustXAddr_brad aborted.


I want to combine every non-numbered line with the previous line.

and end up with:
646 STARTED Tue Dec 30 06:38:53 2008 Job DdCustXAddr_brad has been reset.
647 STARTED Tue Dec 30 06:38:54 2008 Starting Job DdCustXAddr_brad. (...)
704 STARTED Tue Dec 30 06:49:02 2008 Job DdCustXAddr_brad aborted.
  #2 (permalink)  
Old 05-06-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
nawk 'ORS=(FNR%2)?FS:RS' myFile

  #3 (permalink)  
Old 05-06-2009
mfavero mfavero is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 2
great! thanks a lot - what refererences do you recommend to help understand this stuff?
  #4 (permalink)  
Old 05-06-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by mfavero View Post
great! thanks a lot - what refererences do you recommend to help understand this stuff?
'man nawk'
gawk manual
  #5 (permalink)  
Old 05-06-2009
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 to ponder...


Code:
> cat file17
Here is the sample file:
646 STARTED Tue Dec 30 06:38:53 2008
Job DdCustXAddr_brad has been reset.
647 STARTED Tue Dec 30 06:38:54 2008
Starting Job DdCustXAddr_brad. (...)
704 STARTED Tue Dec 30 06:49:02 2008
Job DdCustXAddr_brad aborted.

> cat file17 | sed 's/^[0-9]\{3\}/~&/' | tr "\n" " " | tr "~" "\n"
Here is the sample file: 
646 STARTED Tue Dec 30 06:38:53 2008 Job DdCustXAddr_brad has been reset. 
647 STARTED Tue Dec 30 06:38:54 2008 Starting Job DdCustXAddr_brad. (...) 
704 STARTED Tue Dec 30 06:49:02 2008 Job DdCustXAddr_brad aborted.

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 08:13 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