Rows to column conversion in Solaris


 
Thread Tools Search this Thread
Operating Systems Solaris Rows to column conversion in Solaris
# 1  
Old 11-05-2013
Rows to column conversion in Solaris

i am using the command
Code:
pkginfo -l | /usr/xpg4/bin/grep -e 'VENDOR' -e 'NAME' -e 'VERSION' >> /tmp/test1.txt

in order to get name,vendor and version of the applications installed on Solaris machine.The output stored in test1.txt in as shown below:
Code:
      NAME:  Solaris Zones (Usr)
   VERSION:  11.10.0,REV=2005.01.21.16.34
    VENDOR:  Oracle Corporation
      NAME:  Z shell (zsh)
   VERSION:  11.10.0,REV=2005.01.08.01.09
    VENDOR:  Sun Microsystems, Inc.
      NAME:  Symbios 895A, 896 and 1010 SCSI driver
   VERSION:  11.9.0,REV=2005.01.06.07.16
    VENDOR:  LSI Logic Corporation

I want to have 'NAME' 'VERSION' 'VENDOR' as three separate column as below :
NAME:xyz VERSION:1.1 VENDOR:abc

Last edited by joeyg; 11-05-2013 at 09:10 AM.. Reason: Please wrap commands and data in CodeTags
# 2  
Old 11-05-2013
Try:
Code:
sed 's/^ *//' /tmp/test1.txt | paste -d" " - - -

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 11-07-2013
rows to column conversion

thanks a lot for the help..how can i make the output appear as
Code:
NAME  VERSION  VENDOR
xyz     1.0          oracle
dcr     2.0          gfgf
dvf     3.0          rtrtr


Last edited by Franklin52; 11-07-2013 at 08:21 AM.. Reason: Please use code tags
# 4  
Old 11-07-2013
An nawk solution:
Code:
pkginfo -l | nawk '
        BEGIN {
                printf "%-80s %-40s %-30s\n", "NAME", "VERSION", "VENDOR"
        }
        /NAME:/ {
                nm = $0
                sub ( /NAME:/, X, nm )
                sub ( /^[ ]*/, X, nm )
        }
        /VERSION:/ {
                vr = $0
                sub ( /VERSION:/, X, vr )
                sub ( /^[ ]*/, X, vr )
        }
        /VENDOR:/ {
                vn = $0
                sub ( /VENDOR:/, X, vn )
                sub ( /^[ ]*/, X, vn )
                printf "%-80s %-40s %-30s\n", nm, vr, vn
        }
' OFS="\t"

This User Gave Thanks to Yoda For This Post:
# 5  
Old 11-08-2013
Thank you very much for this script...it is very usefull...thanks a lot again..SmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Conversion of rows to columns using awk based om column value

HI, My Input file data is dn:adcfgeneral id:13343 Name:xxxxxx Password:iutyerwuitywue wpuwt tuiytruityrutyrwtyrwp dn:cdferwjyyyy id:3875 Name:yyyy Password :hgfdsjkfhdsfkdlshf dshfkldshfdklsfh interset:uiuiufj My output should be ... (6 Replies)
Discussion started by: dineshaila
6 Replies

2. Shell Programming and Scripting

Converting Single Column into Multiple rows, but with strings to specific tab column

Dear fellows, I need your help. I'm trying to write a script to convert a single column into multiple rows. But it need to recognize the beginning of the string and set it to its specific Column number. Each Line (loop) begins with digit (RANGE). At this moment it's kind of working, but it... (6 Replies)
Discussion started by: AK47
6 Replies

3. Shell Programming and Scripting

Awk: group rows by id and simple conversion

Hi all, I am a newbie to awk and trying to learn by doing examples. I got stuck at this relatively simple conversion. The start file looks like: 1 2 "t1" 1 3 "h1" 2 1 "h1" 2 2 "h2" and I want to convert it into 1 t1:2, h1:3; 2 h1:1, h2:2; Thanks. (9 Replies)
Discussion started by: eagle_fly
9 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Deleting all rows where the first column equals the second column

Hi, I have a tab delimited text file where the first two columns equal numbers. I want to delete all rows where the value in the first column equals the second column. How do I go about doing that? Thanks! Input: 1 1 ABC DEF 2 2 IJK LMN 1 2 ZYX OPW Output: 1 2 ZYX OPW (2 Replies)
Discussion started by: evelibertine
2 Replies

5. UNIX for Dummies Questions & Answers

Columns to rows conversion in unix

Hi All, My requirement is to convert the rows to columns, please help me how to do in one command. Ex: source file is having data like ABC,XYZ,123,987,KKK,XXX,666 Need output like ABC XYZ 987 KKK XXX 666 Regards, Pavan. (3 Replies)
Discussion started by: madsongtel
3 Replies

6. UNIX for Dummies Questions & Answers

merging rows into new file based on rows and first column

I have 2 files, file01= 7 columns, row unknown (but few) file02= 7 columns, row unknown (but many) now I want to create an output with the first field that is shared in both of them and then subtract the results from the rest of the fields and print there e.g. file 01 James|0|50|25|10|50|30... (1 Reply)
Discussion started by: A-V
1 Replies

7. Shell Programming and Scripting

awk command to print only selected rows in a particular column specified by column name

Dear All, I have a data file input.csv like below. (Only five column shown here for example.) Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 3,2,4,5,6 5,3,5,5,6 From this I want the below output Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 where the second column... (4 Replies)
Discussion started by: ks_reddy
4 Replies

8. Shell Programming and Scripting

complicated row to rows conversion

I have a file containing rows with the following format. Field1|Field2|Field3|data1:data data2:data data3:"dataA:data dataB:data" data4:data:data (and so on) I need to format the above row into multiple rows that look like this: Field1|Field2|Field3|data1|data ... (2 Replies)
Discussion started by: newreverie
2 Replies

9. UNIX for Dummies Questions & Answers

conversion and transpositions of columns and rows

Hi, I am wondering how to do this more efficiently than I am currently doing it: I have these 3 columns 3315 E14 1 397 E14 2 321 E14 3 27 E14 4 7 E14 5 2 E14 6 But I like them to be displayed like this: 1 2 ... (5 Replies)
Discussion started by: danieladna
5 Replies

10. UNIX for Dummies Questions & Answers

How to sum rows in e.g. column 1 by a category in e.g. column 2

Hi, I've shown an example of what I would like to achieve below. In the example file, I would like to sum the values in column 2 for each distinct category in column 3 (presumably making an array?) and print the sum as well as the category name and length (note:length always corresponds with... (8 Replies)
Discussion started by: auburn
8 Replies
Login or Register to Ask a Question