Reputation: 457
I have a large file which is slightly corrupted. The new lines have disappeared. There should have been a new line at every 250th character. How can I fix that?
Thanks in advance.
Upvotes: 1
Views: 2992
Reputation: 47229
There is a command in coreutils
that can wrap lines, it is called fold
:
fold -w 250
Upvotes: 4
Reputation: 41460
An awk
version
awk '{L=250;for (i=1;i<=length($0);i+=L) print substr($0,i,L)}'
Upvotes: 2
Reputation: 195269
try this:
sed -r 's/.{250}/&\n/g'
gawk:
awk -v FPAT='.{1,25}' -v OFS='\n' '$1=$1'
Upvotes: 4
Reputation: 10039
sed 's/^.\{250\}/&\
/;P;D' YourFile
Could be faster on huge file
Upvotes: 2
Reputation: 74705
How about
sed 's/.\{250\}/&\n/g'
The .\{250\}
captures 250 of any type of character. The characters are replaced by themselves, plus a newline.
Upvotes: 5