convert single line output to multiple line

Hi all,

I have a single line output like below

 
echo $ips
10.26.208.28 10.26.208.26 10.26.208.27

want to convert above single line output as below format. Pls advice how to do ?

 
10.26.208.28
10.26.208.26
10.26.208.27

Regards
Kannan

If the value of the variable already has embedded newlines, then all you have to do is quote the variable. If not, you can use the tr utility to convert the embedded whitespace to newlines.

Regards,
Alister

1 Like
 
echo $ips | tr -s " " "\n"
1 Like
echo $ips|xargs -n1
1 Like

Thanks a lot all the reply got it now !!

regards
Kannan

Here's a way using pure shell builtins:

printf "%s\n" $ips
1 Like
echo $ip | perl -pe 's/ /\n/g'

echo $ip | sed 's/ /\n/g'

1 Like