convert single line output to multiple line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting convert single line output to multiple line
# 1  
Old 08-07-2012
convert single line output to multiple line

Hi all,

I have a single line output like below

Code:
 
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 ?

Code:
 
10.26.208.28
10.26.208.26
10.26.208.27

Regards
Kannan
# 2  
Old 08-07-2012
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
This User Gave Thanks to alister For This Post:
# 3  
Old 08-07-2012
Code:
 
echo $ips | tr -s " " "\n"


Last edited by praveen_reddy; 08-07-2012 at 11:35 AM..
This User Gave Thanks to praveen_reddy For This Post:
# 4  
Old 08-07-2012
Code:
echo $ips|xargs -n1

This User Gave Thanks to elixir_sinari For This Post:
# 5  
Old 08-07-2012
Thanks a lot all the reply got it now !!

regards
Kannan
# 6  
Old 08-07-2012
Here's a way using pure shell builtins:

Code:
printf "%s\n" $ips

This User Gave Thanks to Corona688 For This Post:
# 7  
Old 08-07-2012
Code:
echo $ip | perl -pe 's/ /\n/g'

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

This User Gave Thanks to itkamaraj For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies

2. Shell Programming and Scripting

Multiple pattern match and print the output in a single line

I need to match two patterns in a log file and need to get the next line of the one of the pattern (out of two patterns) that is matched, finally need to print these three values in a single line. Sample Log: 2013/06/11 14:29:04 <0999> (725102) Processing batch 02_1231324 2013/06/11... (4 Replies)
Discussion started by: rpm120
4 Replies

3. Shell Programming and Scripting

Splitting Single line into multiple line

Hi All, I am reading a line from a file and writing it to other file. Whenever I got a particular line then I want that line to be splited into 4 line and written it to new file. e.g My line is U_ABC connector3 pin24E connector4 pin25E connector5 pin26E connector6 pin27E connector7... (2 Replies)
Discussion started by: diehard
2 Replies

4. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

5. Shell Programming and Scripting

Joining multi-line output to a single line in a group

Hi, My Oracle query is returing below o/p ---------------------------------------------------------- Ins trnas value a lkp1 x a lkp1 y b lkp1 a b lkp2 x b lkp2 y ... (7 Replies)
Discussion started by: gvk25
7 Replies

6. Shell Programming and Scripting

Merge multi-line output into a single line

Hello I did do a search and the past threads doesn't really solve my issue. (using various awk commands) I need to combine the output from java -version into 1 line, but I am having difficulties. When you exec java -version, you get: java version "1.5.0_06" Java(TM) 2 Runtime... (5 Replies)
Discussion started by: flagman5
5 Replies

7. Shell Programming and Scripting

Output coming in different line instead of single line

Hi Guys, I have an oracle database, I am trying to query the database and route it to file. But the records instead of coming in a single line, are coming in three lines. Can you please help me.. in this.. sqlplus -s $SRMUserid/$SRMPassword@$SRMServer<< EOF >log.out; select * from... (5 Replies)
Discussion started by: mac4rfree
5 Replies

8. Shell Programming and Scripting

make multiple line containing a pattern into single line

I have the following data file. zz=aa azxc-1234 aa=aa zz=bb azxc-1234 bb=bb zz=cc azxc-1234 cc=cc zz=dd azxc-2345 dd=dd zz=ee azxc-2345 ee=ee zz=ff azxc-3456 ff=ff zz=gg azxc-4567 gg=gg zz=hh azxc-4567 hh=hh zz=ii azxc-4567 ii=ii I want to make 2nd field pattern matching multiple lines... (13 Replies)
Discussion started by: VTAWKVT
13 Replies

9. Shell Programming and Scripting

single line input to multiple line output with sed

hey gents, I'm working on something that will use snmpwalk to query the devices on my network and retreive the device name, device IP, device model and device serial. I'm using Nmap for the enumeration and sed to clean up the results for use by snmpwalk. Once i get all the data organized I'm... (8 Replies)
Discussion started by: mitch
8 Replies

10. Shell Programming and Scripting

Multi-line output to single line

Hello, How can I take the following output: outputa outputb outputc and turn it into single line ouput, with a single space between each field like below: outputa outputb outputc (7 Replies)
Discussion started by: LinuxRacr
7 Replies
Login or Register to Ask a Question