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

Seperate lines on a file 1

Status
Not open for further replies.

IMAUser

Technical User
May 28, 2003
121
CH
I have a file with about 50K records, but the problem is there are no newline characters anywhere. So it all appears as one huge line. I know where the newline char should be ( after 300 chars), but is there a way to do this.
I have used 'cut' to do the job in a while loop ( I also know the end condition), but this is very slow.
Does anyone know of a command or a simpler way of doing this.

Thanks,
 
Or try fold

fold -300 infile > outfile

CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Or even:
Code:
split -b300 <file> <split file prefix>
eg:
Code:
split -b300 file split.
Cheers, Neil
 
Thanks for all the help.
I have used fold to do the trick ( Easy to remember). But there is slight problem. My file actually contains 13750 records, I know this because there is a trailer record which tells me how many records to expect. This trailer record is also the last record on the file.
When I vi my outfile I can see 13750 records, but if I do a wc -l filename it comes back with only 13749. I cant understand why this is happening. So will need some more inputs from you experts.
Thanks,
 
My guess is that fold is not putting a linefeed after the last line and wc counts lines by counting linefeeds. In vi, try opening a line at the end of the file, then deleting the blank line and saving the file. Alternatively, try

awk '{print}' outfile > outfile2

CaKiwi

&quot;I love mankind, it's people I can't stand&quot; - Linus Van Pelt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top