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 lines in files sme Shell Programming and Scripting 14 10-17-2008 04:47 AM
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
Search file for pattern and grab some lines before pattern frustrated1 Shell Programming and Scripting 2 12-22-2005 03:41 PM
Combining multiple lines DUST Shell Programming and Scripting 4 07-15-2005 11:57 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 08-26-2008
shell.scriptor shell.scriptor is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 2
combining lines between 2 pattern using awk

Hi

I am fairly new to shell scripting
i have some file with outout
1011
abc fyi
6.1.4.5

abr tio
70986
dfb hji
4.1.7
....some text
111114

i have to format this text to

1011 abc fyi 6.1.4.5 abr tio
70986 dfb hji 4.1.7 ....some text
111114

basically combine the lines between the patterns that have whole numbers
is this possible in a simple awk script?

Thanks much
  #2 (permalink)  
Old 08-26-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Use printf to print a space and the current line without a trailing newline. When you see a new integer or end of file, printf a newline and the current line.
  #3 (permalink)  
Old 08-26-2008
shell.scriptor shell.scriptor is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 2
Thanks era

do have a code snipet i could use

Thanks
  #4 (permalink)  
Old 08-26-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
I didn't, but now I do.

Code:
awk '$1 ~ /^[1-9][0-9]*$/{ if (NR > 1) printf "\n"; printf "%s", $0; next; }
{ printf " %s", $0; }
END { printf "\n" }' filename
The integer test feels kind of inelegant, I guess there must be a better way to do it.
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 07:38 PM.


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