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!

Need help creating a delimited file

Status
Not open for further replies.

ryanc2

MIS
Apr 18, 2003
73
US
Need help with this portion of a script to create a delimited list:

disks=`df -v | grep /dc/d | awk '{print $1}'`

this gives me a list of drives as:

/du0
/du1
/du2
/du3

I want it to look like /du0|/du1|/du2|/du3

when I echo $disks, it returns:

/du0 /du1 /du2 /du3

I'm guessing these are not spaces between the variables, just how it is being read. How can I set the disks variable to be /du0|/du1|/du2|/du3 so I can read into an array?

Any help would be appreciated.
 
Hi:

I think this might do it:


disks=`df -v | grep /dc/d | awk '{printf("%s|", $1)}'`

Then you have to get rid of the last pipe ?

echo $disks|sed 's/|$//g'
 
Maybe

disks=`df -v | grep /dc/d | awk '{printf pp $1;pp="|"}'`


CaKiwi
 
Thanks to both of you...I've got what I needed!
 
paste can be used to join subsequent lines with delimiter...

disks=`df -v | grep /dc/d | paste -s -d'|'`

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top