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!

joining lines

Status
Not open for further replies.

chalcopyrites

Technical User
Mar 11, 2004
12
GB
Hi,

I hope you can help me. I have a file like this:

300.0757
-999.2500 23.0000 -999.2500 -999.2500 -999.2500
-999.2500 -999.2500 -999.2500 -999.250000 -999.2500
-999.2500 -999.2500 -999.2500 -999.250000 -999.2500
-999.2500 -999.2500 -999.250000 -999.2500 -999.2500
-999.2500 -999.2500 -999.2500 -999.2500
300.2281
-999.2500 23.0000 -999.2500 -999.2500 -999.2500
-999.2500 -999.2500 -999.2500 -999.250000 -999.2500
-999.2500 -999.2500 -999.2500 -999.250000 -999.2500
-999.2500 -999.2500 -999.250000 -999.2500 -999.2500
-999.2500 -999.2500 -999.2500 -999.2500
300.3805
-999.2500 23.0000 -999.2500 -999.2500 -999.2500
-999.2500 -999.2500 -999.2500 -999.250000 -999.2500
-999.2500 -999.2500 -999.2500 -999.250000 -999.2500
-999.2500 -999.2500 -999.250000 -999.2500 -999.2500
-999.2500 -999.2500 -999.2500 -999.2500
....etc

Every 6 lines is a block of data I would like to have on a single line. I know awk '{printf("%s",$0)}' ip > op will put everything onto one line (upto a certain limit) but I dont know how to tell it to do this to blocks of 6 lines.

I would be interested to see what you suggest,

Many thanks

Erica
 
this?

Code:
awk '{
      if ((NR>1) && ((NR%6)==0))
       printf "\n"
      printf "%s ", $0
     }
     END{
      printf "\n"
     }' /path/to/file

HTH,

p5wizard
 
In unix you may use the paste command:
cat /path/to/input | paste - - - - - -

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for both of your replies. That paste one is really cool, I had never thought of using that.

Thanks again

Erica
 
BTW, we are in the awk forum:
awk '{printf "%s%s",$0,(NR%6?" ":"\n")}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top