![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
| Display Modes | Rate This Thread |
|
|