regex - How do I force lines to be a certain length? -


i have text file contains large list of 5-digit numbers. lines contain more 1 5-digit number without newline separating them

12345 23456 34567 4567856789 67890 ... 837460174975917 ... 

i'm trying find regular expression can use sed add newlines in-between numbers.

the desired output be:

12345 23456 34567 45678 56789 67890 ... 83746 01749 75917 ... 

i've played around bit, best can figure out ^([0-9]{5}) replaced $1/r/n. however, adds newline after every digit, , i'd need remove blank lines afterwards not optimal because of size of file.

light weight solution using fold :

sample input:

cat filename 12345 23456 34567 4567856789 

solution using fold:

cat filename|fold -w5 12345 23456 34567 45678 56789 

update(as suggested kenavoz): avoid unnecessary use of cat , pipe

fold -w5 filename  

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -