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
split a filename and print to 2 different headings mbak AIX 3 10-15-2008 12:31 AM
Split a file with no pattern -- Split, Csplit, Awk madhunk UNIX for Dummies Questions & Answers 10 12-17-2007 12:57 PM
Print to ps2pdf print queue Sean_69 SUN Solaris 2 10-22-2007 12:00 PM
Print Problem in UNIX. Need to know the option to specify the print paper size ukarthik HP-UX 1 06-07-2007 10:35 AM
split and print $PATH umen Shell Programming and Scripting 2 06-06-2006 11:10 AM

 
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
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 10-27-2008
dcfargo dcfargo is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 45
Split and print

I have a file with data such as:


X Y Z 4 1,3,5,7, 4,6,8,10,
A B C 3 2,3,4, 5,9,11,
E F G 5 1,2,3,4,5, 8,9,10,11,12,


Columns 1, 2 and 3 are descriptions. Column 4 tells how many numbers are in columns 5 and 6

What I'd like to do is split column 5 and column 6 by the "," and then print out a line with columns 1, 2, 3, 4, and the 1st number from column 5 and column 6, then print out a line with columns 1, 2, 3, 4,and the 2nd number in cols 5 and 6 ... until all the numbers in 5 and 6 are printed.

X Y Z 4 1 4
X Y Z 4 3 6
X Y Z 4 5 8
X Y Z 4 7 10

A B C 3 2 5
A B C 3 3 9
A B C 3 4 11

E F G 5 1 8
E F G 5 2 9
E F G 5 3 10
E F G 5 4 11
E F G 5 5 12



I was trying something like:

awk '{
split($5,a,",");
split($6,b",");
for (i=1; i<= $4; i++)
print $1,$2,$3, a[i], b[i]
}’
infile > outfile &


This isn't working

Thank you so much.

edit:

%$#%# I just messed up the syntax it works if I can use the commas correctly

split($5,a, ",");
split($6,b, ",");

Sorry
 

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:00 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