The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-26-2008
astroDave astroDave is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 2
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
  #2 (permalink)  
Old 03-27-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,913
Replace "for (n=0;n" with

Code:
   for (n=0; n<rows; n++) {
      print row[n]
   }
}
  #3 (permalink)  
Old 03-27-2008
astroDave astroDave is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 2
Thanks - that works much better!
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 09:58 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