Need help with extracting field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with extracting field
# 1  
Old 06-08-2010
Power Need help with extracting field

hi there,

i'm new to shell scripting as i usually just use our solaris server for db administration and to get some basic system information. however i'm stuck with something that requires further scripting knowledge.

I need to extract the Name, Desc and Status from pkginfo-l.

I need them to be sorted like first column for Name, second column for Desc and third column for Status.

and all these without the words "NAME", "DESC" and "STATUS" appearing. can somebody please help me?

I believe awk is needed and I'm a newbie to sed
# 2  
Old 06-08-2010
Try:
Code:
pkginfo -l |
awk -F":  " '
/NAME:/{s=$2} 
/DESC:/{s=s "," $2} 
/STATUS:/{print s "," $2}'

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 06-08-2010
Thanks Franklin, but i'm sorry i wasn't as precise as i should have been.

i need them aligned in such a way that that would fit into an excel table according to the name, desc and status column. the commas are not needed either. could you please me a little further here? thanks.
# 4  
Old 06-08-2010
You can redirect the output to a file with a .csv extension and open it with Excel.

Regards
# 5  
Old 06-08-2010
Thanks Franklin, i did that first however the problem I have is that when I use the comma delimiter in excel to get them into separate columns, it doesn't work for many rows. simply because there are many commas in the DESC itself. therefore it gets broken up into more than three columns. how do i fix this problem? thank you.
# 6  
Old 06-09-2010
this sounds like problem have move from unix table to spreadsheet one !!!

if using MS excel, try exploring into data->Text to Column wizard.
might be that can solve your purpose.
# 7  
Old 06-09-2010
Instead of comma separated, try pipe separated and open the file in excel by going to Data ->Import External Data

Code:
pkginfo -l |
awk -F":  " '
/NAME:/{s=$2} 
/DESC:/{s=s "|" $2} 
/STATUS:/{print s "|" $2}' > Your_file.txt

This User Gave Thanks to rajdeep_paul For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table ACN|NAME|CITY|CTY|NO1|NO2 115|AKKK|ASH|IND|10|15 115|AKKK|ASH|IND|20|20 115|AKKK|ASH|IND|30|35 115|AKKK|ASH|IND|30|35 112|ABC|FL|USA|15|15 112|ABC|FL|USA|25|20 112|ABC|FL|USA|25|45 i have written shell script using cut command and awk programming getting error correct it and add... (5 Replies)
Discussion started by: udhal
5 Replies

2. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

3. Shell Programming and Scripting

Extracting field values from .csv

How can I select the bold fields from the following? "CLLI","SWREL","RPTDATE","RPTIME","TZ","RPTTYPE","RPTPD","IVALDATE","IVALSTART","IVALEND","NUMENTIDS" "tklc9010801","EAGLE5 45.0.0-64.70.1","2013-08-07","02:01:50","MST ","COMPONENT MEASUREMENTS ON... (4 Replies)
Discussion started by: leghorn
4 Replies

4. Shell Programming and Scripting

awk - extracting a field

Hi all, I have automated a process of doing a sanity check for the DDL created by other DBA's. But i am stuck at a point. while reading a file in the awk, PI of the table is defined as )PRIMARY INDEX test_abc(ACCT_ID) PARTITION BY RANGE_N(AUTHZN_MTCH_IND BETWEEN DATE '2011-10-01' AND... (1 Reply)
Discussion started by: ysvsr1
1 Replies

5. Shell Programming and Scripting

Extracting duplicates from a desired field

Hello, I have a file of group names and GID's (/etc/group) and I want to find the duplicate group names and put them in a file. So there are 2 fields, i.e.: audit 10 avahi 70 avahi-autoipd 103 bellrpi 605 bin 1 bin 2 bord 512 busobj 161 bwadm 230 cali81 202 card 323 cardiff 901 cbm... (2 Replies)
Discussion started by: mgb
2 Replies

6. Shell Programming and Scripting

awk, comma as field separator and text inside double quotes as a field.

Hi, all I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes. sample input: for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Discussion started by: kevintse
8 Replies

7. Shell Programming and Scripting

Extracting field from array

I have a problem with the following lines of code: SaveIFS=$IFS IFS="/" declare -a Array=($1)#take unix path, split by '/' website=${Array} #stores website name The confusing part is that it works on one machine, but not on the other. If the code is... (2 Replies)
Discussion started by: montana24
2 Replies

8. Shell Programming and Scripting

Extracting a field value from a line

Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.12.11.255)(PORT = 1540)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = CSMFIRE03))) I would like to extract the CSMFIRE03. I have no clue which command to use. Could... (5 Replies)
Discussion started by: Naresh Akkal
5 Replies

9. Programming

Extracting Field values for XML file

i have an input file of XML type with data like <nx-charging:additional-parameter name="NX_INTERNATIONALIZED_CLID" value="919427960829"/><nx-charging:finalStatus>RESPONSE , Not/Applicable , OK</nx-charging:finalStatus></nx-charging:process> i want to extract data such that i get the output... (3 Replies)
Discussion started by: junaid.nehvi
3 Replies

10. Shell Programming and Scripting

extracting a field from directory path ??????

Hi I'll be getting a directory path as the input to the script. E.g. 1 abc/fsg/sdfhgsa/fasgfsd/adfghad/XXX/fhsad e.g. 2 sadfg/sadgjhgds/sd/dtuc/cghcx/dtyue/dfghsdd/XXX/qytq This input will be stored in a variable. My query is how to extract the field in a variable VAR which occurs... (15 Replies)
Discussion started by: skyineyes
15 Replies
Login or Register to Ask a Question