Multi-line output to single line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multi-line output to single line
# 1  
Old 02-25-2008
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
# 2  
Old 02-25-2008
presume this is the output from a script. You can change your script to display in the same line instead of printing in the newline.
Eg :-

echo "outputa\c "
echo "outputb\c "
echo "outputc"

'\c' in the above echo will make sure next echo to print in the same line.
# 3  
Old 02-25-2008
correct, but you may have to use -e option with echo to get the \c interpreted.

-ilan
# 4  
Old 02-25-2008
am on solaris and using Bourne shell which doesn't require '-e' option Smilie
# 5  
Old 02-25-2008
Mani, thanks again for correcting me; i am not much aware of Solaris.
# 6  
Old 02-25-2008
have a look at the man page for tr.

What you probably want here is:

Code:
tr "\n" " " < infile

# 7  
Old 02-25-2008
Thanks for all the replies. I also ended up finding this solution that fit:

Code:
awk -v x="" '{ s=s sprintf(x "%s" x " ", $0) } END { sub(",$", "", s); print(s) }' file.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multi line log files to single line format

I want to read the log file which was generate from other command . And the output was having multi line in log files for job name and server name. But i need to make all the logs on one line Source file 07/15/2018 17:02:00 TRANSLOG_1700 Server0005_SQL ... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

2. Shell Programming and Scripting

Help with reformat single-line multi-fasta into multi-line multi-fasta

Input File: >Seq1 ASDADAFASFASFADGSDGFSDFSDFSDFSDFSDFSDFSDFSDFSDFSDFSD >Seq2 SDASDAQEQWEQeqAdfaasd >Seq3 ASDSALGHIUDFJANCAGPATHLACJHPAUTYNJKG ...... Desired Output File >Seq1 ASDADAFASF ASFADGSDGF SDFSDFSDFS DFSDFSDFSD FSDFSDFSDF SD >Seq2 (4 Replies)
Discussion started by: patrick87
4 Replies

3. 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

4. UNIX for Dummies Questions & Answers

Remove multi line and single line comments

Hi, I am trying to remove multi line and single line comments like examples below I have tried this pattern. it works fine for single line comments and multi line comments in a single line only. but this fails when the comments are extended in multiple lines as shown in the comment 2 of... (3 Replies)
Discussion started by: ahmedwaseem2000
3 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

How to use Perl to join multi-line into single line

Hello, Did anyone know how to write a perl script to merge the multi-line into a single line where each line with start at timestamp Input--> timestamp=2009-11-10-04.55.20.829347; a; b; c; timestamp=2009-11-10-04.55.20.829347; aa; bb; cc; (5 Replies)
Discussion started by: happyday
5 Replies

8. Shell Programming and Scripting

How to use Perl to merge multi-line into single line

Hi, Can anyone know how to use perl to merge the following multi-line information which beginning with "BAM" into one line. For each line need to delete the return and add a space. Please see the red color line. ******Org. Multi-line) BAM admin 101.203.57.22 ... (3 Replies)
Discussion started by: happyday
3 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

Making multi line output appear on one line

Basically I wanna take grep output, EACH_OPTION_CHARGE: V033*, VMVM, 4.00, M EACH_OPTION_CHARGE: V040*, VMVM, 4.00, M EACH_OPTION_CHARGE: V042*, VMVM, 4.50, M EACH_OPTION_CHARGE: V043*, VMVM, 5.00, M EACH_OPTION_CHARGE: V050*, VMVM, 4.00, M EACH_OPTION_CHARGE: V052*,... (1 Reply)
Discussion started by: djsal
1 Replies
Login or Register to Ask a Question