cancel
Showing results for 
Search instead for 
Did you mean: 

sed - insert spaces on line

Simpson
Occasional Advisor

sed - insert spaces on line

I have a file that contains a date on each line. I would like to up date the formate by doing the following:

orig_file:
20090208
20090209

new_file
2009 02 08
2009 02 09

Any help would be appreciated.
Thanks
Mike
2 REPLIES
Michael Mike Reaser
Valued Contributor

Re: sed - insert spaces on line

Instead of sed, try awk:

awk '{printf("%s %s %s\n",substr($0,1,4),substr($0,5,2),substr($0,7,2))}' < orig_file > new_file
There's no place like 127.0.0.1

HP-Server-Literate since 1979
Hein van den Heuvel
Honored Contributor

Re: sed - insert spaces on line

$ sed -e 's/\(....\)\(..\)\(..\)/\1 \2 \3/' old.txt > new.txt


Hein.