Input file:
aaaa bbb dd.
qqq wwww e.
Output file:
a a a a <s> b b b <s> d d .
q q q <s> w w w w <s> e .
Can I use sed to do so in one step?
Input file:
aaaa bbb dd.
qqq wwww e.
Output file:
a a a a <s> b b b <s> d d .
q q q <s> w w w w <s> e .
Can I use sed to do so in one step?
awk '{for(i=1;i<=NF;i++) printf "%s ",$i; print ""}' FS="" infile
a a a a b b b d d .
q q q w w w w e .
Thanks!
But how can I also add <s> in the previously existing spaces?
awk '{a="";for(i=1;i<=NF;i++) a=a sprintf("%s ",$i);gsub(/ /," <s> ",a);print a}' FS=""
a a a a <s> b b b <s> d d .
q q q <s> w w w w <s> e .
I thought the <s>
was representing space, but this fix it.
sed 's/./& /g; s/[[:blank:]]\{2,\}/ <s> /g'
Without an extra space at the end:
sed 's/./& /g; s/[[:blank:]]\{2,\}/ <s> /g; s/ $//'
Based on MadeInGermany sed you can tweak my regex some
Did forget the nice &
awk '{gsub(/./,"& ");gsub(/ /," <s> ")}1'
If you like to remove the extra space added after final letter .
in all example above add $1=$1
awk '{gsub(/./,"& ");gsub(/ /," <s> ");$1=$1}1'