Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AWK, reformating single line file into one line output

Status
Not open for further replies.

ErrolDC

MIS
May 26, 2004
72
US
Hi everyone. I want to read a file that consists of single line entries and output them as one line, space seperated. Text and file manipulation is not my best skill. Can someone point me in the right direction? Is AWK the tool I need? Any examples?
 
sorry, what I meant was multi-line into single line output
 
Any chance you could post some input samples and expected result as your request is quite vague.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Sure. The is a list of oracle instances. One instance per line. I want to feed them into the korn shell so as to create an array.

So, if the file looks like

foo1
foo2
foo2

I need it reformated as:

foo1 foo2 foo3

Thanks
 
One way:
tr '\012' ' ' < /path/to/input > output
Another way:
awk 'BEGIN{ORS=" "}1' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Or
Code:
paste -s -d " " input >output


Option Meanings

[tt]-s[/tt]: Normally, [tt]paste[/tt] joins corresponsing lines of several files. This tells it to join lines sequentially.

[tt]-d " "[/tt]: Normally, [tt]paste[/tt] separates fields with a tab character. This tells it to use a space as a delimiter instead.
 
Chacalinc's suggestion worked for me. I did %s\t because I needed some sort of space to substitute for the newline

Thanks everyone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top