Change one line to multiple

I did help some at another forum to change one line to multiple lines.

var1="abc001: text goes here yyy003: text goes here uuuu004: text goes here"

Running this awk , gives correct result, but its not very nice. Any idea on how to simplify it?

awk '{for (i=1;i<=NF;i++) printf $i~":"?"\n"$i" ":$i" "}' <<< "$var1"| awk 'NF {sub(/:/,x);print}'
abc001 text goes here
yyy003 text goes here
uuuu004 text goes here

Change to one line, remove :

awk '{ gsub(/([^ ]*): /, "\n\1"); sub(/^\n/,""); } 1'

Thanks Corona, but hostname is missing.

Another awk

awk '{gsub(/[a-zA-Z]+[0-9]+/,"\n&");gsub(/:|^\n/,x)}1' <<< "$var1"
abc001 text goes here
yyy003 text goes here
uuuu004 text goes here

^/n did help me to remove the blank line

Perl solution:

perl -0pe 's/://;s/(\w+):/\n$1/g' <<< "$var1"
1 Like

Hello,

One more approach.

echo $var1  | awk 'gsub(/\:/,X) gsub(/here /,"here\n");'

Output will be as folllows.

abc001 text goes here
yyy003 text goes here
uuuu004 text goes here

Thanks,
R. Singh

@R.Sing
Will not work, sine this is just an example text and it will change.
One static is the :

You could also do bartus11's trick in sed:

sed -r 's/://;s/(\w+):/\n\1/g' <<< "$var1"
sed -r 's/([^[:space:]]*):/\n\1/g' <<<"$var1"

abc001 text goes here 
yyy003 text goes here 
uuuu004 text goes here