![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| Convert two column data into 8 columns | NickC | Shell Programming and Scripting | 8 | 06-28-2008 11:19 AM |
| How to convert a single column into several rows and columns? | ashton_smith | UNIX for Dummies Questions & Answers | 5 | 05-24-2008 04:44 PM |
| How to check Null values in a file column by column if columns are Not NULLs | Mandab | Shell Programming and Scripting | 7 | 03-15-2008 09:57 AM |
| single column to multiple columns | agibbs | UNIX for Dummies Questions & Answers | 7 | 12-05-2007 10:04 PM |
| Print last 4 columns (variable column #) | Da_Duck | UNIX for Dummies Questions & Answers | 19 | 02-27-2004 10:33 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Single column to multiple columns in awk
Hi -
I'm new to the awk programming language. I'm trying to print a single column of data to several columns, and I found an article on iTWorld.com (ITworld.com - Printing in columns). It looks like the mkCols2 script is very close to what I need to do, but it looks like the end of the code has been cut off, and the author's contact email doesn't seem to work. Does anyone know how the mkCols2 script might end? Thanks, Dave Code: # mkCols2 -- organize input into columns # BEGIN { padding=" " widestCell=1 } { cell[NR-1]=$0 if ( length($0) > widestCell ) widestCell=length($0) # save widest data } END { x=((NR+(cols-1))/cols) rows=x-(x % 1) # calculate number of rows req'd maxCol=widestCell+2 # calculate column width for (n=0; n<=NR; n++) { # for each input line pad=substr(padding,1,(maxCol-length(cell[n]))) rownum=n % rows row[rownum]=row[rownum] cell[n] pad # add req'd padding } for (n=0; n |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|