The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to transpose data elements in awk ahjiefreak Shell Programming and Scripting 2 05-13-2008 04:44 AM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 09:57 AM
Row to column transpose videsh77 Shell Programming and Scripting 10 06-16-2007 12:54 PM
transpose command su_in99 UNIX for Dummies Questions & Answers 3 05-16-2007 05:10 AM
Replace 10th column with a new column--- Terriblly hurry ahmedwaseem2000 Shell Programming and Scripting 2 09-06-2005 01:10 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-01-2008
m223464 m223464 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 41
How do I transpose a column of results to a row

Hi,

Can anyone advise me what command I could use to display the results of the following command as a row.

Quote:
i.e. Display this

$ lslpp -l|grep tsm
tivoli.tsm.books.en_US.client.pdf
tivoli.tsm.client.api.32bit
tivoli.tsm.client.api.64bit
tivoli.tsm.client.ba.32bit.base
tivoli.tsm.client.ba.32bit.common
tivoli.tsm.client.ba.32bit.image
tivoli.tsm.client.ba.32bit.nas
tivoli.tsm.client.ba.32bit.web

Like this

tivoli.tsm.books.en_US.client.pdf tivoli.tsm.client.api.32bit tivoli.tsm.client.api.64bit etc
Thanks

Gareth
  #2 (permalink)  
Old 05-01-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Code:
lslpp -l | grep tsm | tr '\n' ' '
  #3 (permalink)  
Old 05-01-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
If you prefer a newline character after the line:

Code:
lslpp -l|awk '/tsm/{ORS=" "}{print}END{print "\n"}' file
  #4 (permalink)  
Old 05-01-2008
m223464 m223464 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 41
Quote:
Originally Posted by robotronic View Post
Code:
lslpp -l | grep tsm | tr '\n' ' '
Thanks for this code. It's doing exactly what I asked but unfortunately my plan to use the resulting output as input to another command isn't working.
I was trying to use this as input to the command below, however it's only processing the first item in the list.

Code:
sm_inst installp_cmd -u -f `lslpp -l|grep tsm| tr '\n' ' '`
If I was to type the filesets in manually the command would be as shown below but placing `lslpp -l|grep tsm| tr '\n' ' '` within the quotes doesn't work at all.

Code:
sm_inst installp_cmd -u -f'fileset-1 fileset-2'

I did try the other suggestion but just got an error
Code:
lslpp -l|awk '/tsm/{ORS=" "}{print}END{print "\n"}' file
awk: 0602-533 Cannot find or open file file.
 The source line number is 1.
Can anyone suggest a more sensible and succesful way of implementing this?

thanks

Gareth
  #5 (permalink)  
Old 05-01-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
What about putting the filelist into a variable and let work the shell expansion?

Code:
LIST=`lslpp -l | grep tsm | tr '\n' ' '`
sm_inst installp_cmd -u -f "$LIST"
You have to use double quotes instead of single ones. Maybe you can also get rid of the tr command.
  #6 (permalink)  
Old 05-01-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Quote:
Originally Posted by m223464 View Post
I did try the other suggestion but just got an error
Code:
lslpp -l|awk '/tsm/{ORS=" "}{print}END{print "\n"}' file
awk: 0602-533 Cannot find or open file file.
 The source line number is 1.
Oops, you don't read from a file, you can remove that:

Code:
 lslpp -l|awk '/tsm/{ORS=" "}{print}END{print "\n"}'
Regards
  #7 (permalink)  
Old 05-06-2008
m223464 m223464 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 41
All working now.

Thanks to both you guys for your assitance and apologies to franklin52 for being a bit stupid when trying to run your command.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0