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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rearranging Dataset: 2

Status
Not open for further replies.

hill007

Technical User
Mar 9, 2004
60
US
I had submitted this same question previously, but the code did not work as I intended. What it did, put all the datasets in one line.
I want to place every first three rows in one line, please see the output file.
Both vgersh99 and futurelet's code puts everything in one row. Which is not intended.
Thanks.


I have a input file as:

A B C
D E F
G
1 2 3
4 5 6
7


My output should look like this:
A B C D E F G
1 2 3 4 5 6 7

How do I do this?

Thanks a lot.


vgersh99 (Programmer) Mar 10, 2004
something like this:

NF == 1 { print $0;next }
{printf("%s ", $0) }

vlad

futurelet (Programmer) Mar 10, 2004
For uniform spacing:

CODE
1==NF { print; next}
{$1=$1; printf "%s ", $0 }

 
Something like this ?
{printf "%s "}
NR%3==0{printf "\n"}
END{if(NR%3)printf "\n"}

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
PHV,

The code do not works. Awk gives an error "not enough arguments in printf(%s).
Thanks.
 
Sorry for the typo:
{printf "%s ",$0}
NR%3==0{printf "\n"}
END{if(NR%3)printf "\n"}

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Merges three lines into one, with uniform spacing:
Code:
{$1=$1; if (0==NR%3) print $0
        else printf "%s ", $0}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top