Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CREATING COLUMNS FROM A SINGLE COLUMN FILE 1

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
I have a file that has a list of numbers in the first and only column. To shorten the output I would like to create a multiple column output.

I am attempting to use something like the following:

cat filename | nawk 'BEGIN{ FS="\n"; RS=""; OFS="\n"}{print $1, $2, $3, $4}'

Obviously that's not right because it's not working, but I can't seem to figure out what to do to get the output to look like the example below:

12345 234231243 12312 1234233
132134 894388 1241234 12341234

Any help would be greatly appreciated.

Thanks,

John
 
something like that to start with:

BEGIN {
if (cols == "")
cols=4;
}

{ printf("%-10s %s", $0, (FNR % cols) ? "" : "\n") }
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Vlad,

That works great!! Thanks!! Is there another way to do this using something like the example I provided in my first post?

Thanks,

John
 
here's another way - a variation on my previous 'theme'. I don't think you can do anything similar yours though.

#--------------------
BEGIN {
if (cols == &quot;&quot;)
cols=4;
}

{ printf(&quot;%-10s &quot;, $0) }
!(FNR % cols) {print &quot;\n&quot;}

#----------------------
#----------------------
#----------------------
# here's script going the other way - multiple columns to
# the single column rows:
BEGIN {
OFS=&quot;\n&quot;
}
$1=$1 vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top