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

Breaking down a long, long line of numbers

Status
Not open for further replies.

CG101

Technical User
Jun 12, 2003
6
NZ
Hi,

I have an image written in ascii text format, with the data all on one long line. I would like to split this up so that each data value is on a new line.

So, I have:

Header
Header
1.123456 12.123456 123.123456 12.123456 ...etc

And I would like to produce:

Header
Header
1.123456
12.123456
123.123456
...

The UNIX 'fold' command won't work because of the differing numbers of characters in each data value.

Also the line goes on for several hundred thousand characters. I hear that awk has limitations on line length - can these be avoided, or is this simply impossible with awk?

Suggestions in anything other than awk are also welcome.

Thanks.
 
Use gawk.
Then use substr() for your line division.
 
Thanks for the swift reply.

Unfortunately I do not seem to have gawk. I am using Solaris 5.8, and have awk and nawk but not gawk.

Any other suggestions?
 
nawk -v OFS="\n" '{$1=$1; print}' file.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks, but this doesn't overcome the line length problem. It works for short lines, but when I try it on my image with a line length of 4314016 bytes, I get the error:

nawk: input record '1309.000000 1309.000...' too long
input record number 5, file file1
source line number 1

Is the awk/nawk line length limit fixed in stone or is there a way to read longer lines?

Cheers.
 
try /usr/xpg4/bin/awk

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
or you can try:

tr ' ' '\n' < file.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
tr ' ' '\n' < file1

=> works a treat.

Thanks for your time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top