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!

howto make a list to a string 2

Status
Not open for further replies.

valle70

IS-IT--Management
Jun 11, 2004
6
DK
Hi
How can i convert a list to a string?
I have following list:

node1
node2
node3
node4

And i would like to convert this list to:

node1, node2, node3, node4

How do i do this?

Regards Valle70

 
Code:
nawk -v RS='' -v OFS=',' '$1=$1' file

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
You can use tr :

tr '\n' ',' < sourcefile

will translate all newlines in the file to commas. I suspect you'll get a better answer from an awk user though...



 
There you are you see. In the time it took me to type "you'll get a better answer from an awk user" ...
 
[tongue]

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi:

How about using xargs?

cat file|xargs

Regards,


Ed
 
In ksh...
[tt]
list=$(<file1)
[/tt]
Or perhaps...
[tt]
list=$(echo $(<file1)|sed 's/ /, /g')[/tt]
 
Hi
Thanks for all your answears.
It seems there is serveral ways to do this.


Regards Valle70
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top