linux - How can i echo the newline after everyline -


my host red hat enterprise linux server release 5.4 bash.
when use command: netstat -tnpl | grep "tcp" | awk '{print $4}',than output following:

127.0.0.1:2208 0.0.0.0:871 0.0.0.0:9001 0.0.0.0:3306 0.0.0.0:111 127.0.0.1:631 127.0.0.1:25 127.0.0.1:6010 127.0.0.1:6011 127.0.0.1:2207 :::80 :::22 :::8601 ::1:6010 ::1:6011 :::443   

but when use this: ip_port=`netstat -tnpl | grep "tcp" | awk '{print $4}'` && echo $ip_port,it becomes following:

127.0.0.1:2208 0.0.0.0:871 0.0.0.0:9001 0.0.0.0:3306 0.0.0.0:111 127.0.0.1:631 127.0.0.1:25 127.0.0.1:6010 127.0.0.1:6011 127.0.0.1:2207 :::80 :::22 :::8601 ::1:6010 ::1:6011 :::443   

it becomes online. how did happen , want original format.

you need enclose variable in quotes when echoing:

echo "$ip_port" 

also, don't need use both grep , awk because awk can grep. can simplify command to:

netstat -tnpl | awk '/tcp/{print $4}' 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -