The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: Transpose Rows
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 03-17-2009
iamwha1am iamwha1am is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 4
Transpose Rows

Hi,

Am trying to transpose a set of rows into a set of comma separated values.

For eg. if the output of

ps -ef | tail +2 | awk 'BEGIN{ FS=" " } { print $2 }'

is

0
1
3
4

I need to transpose it to -

'0','1','3','4'

Am currently trying -

ps -ef | tail +2 | awk 'BEGIN{ FS=" " } { print $2 }' | tr '\n' ',' > tmpFile
sessList=`cat tmpFile | sed s/.$/\'/ | sed s/^/\'/ | sed s/\,/\'\,\'/ `
echo $sessList

However that does not seem to work.

Any pointers towards achieving this more efficiently/elegantly will be of great help.