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

line break every two fields 1

Status
Not open for further replies.

jkluesner

Technical User
Sep 29, 2006
24
US
Hello all,

I know this is a simple question, however I haven't used awk in over a year and am having memory issues... (must be that I turned 30 last week).

Anyway, I want to take a txt file with 8 fields on one line and add line breaks every two fields. For example the file looks like this:

0 1538 10 1539 20 1537 30 1533
40 1529 50 1523 60 1519 70 1516
80 1513 90 1510 100 1509 110 1508
120 1506 130 1505 140 1505 150 1504


I want to rearrange the fields to look like this:

0 1538
10 1539
20 1537
30 1533
40 1529
50 1523 ... etc

Any help will be greatly appreciated!

-J
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I have this so far:

awk '{for(i=1;i<NF;i++)if(i%2==0){$i=$i"\n"} }1' U1414_velocity_function.txt

However my output looks like this:

Code:
0 1538
 10 1539
 20 1537
 30 1533
40 1529
 50 1523
 60 1519
 70 1516
80 1513
 etc...

I am not sure why it is adding a space on the 2nd, 3rd, and 4th rows of each loop...
 
What about this ?
awk '{for(i=1;i<NF;i+=2)print $i,$(i+1)}' U1414_velocity_function.txt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Save the call to awk:

Code:
xargs -n 2 < U1414_velocity_function.txt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top