How to get column names?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to get column names?
# 1  
Old 11-08-2013
How to get column names?

Hi Everybody,

if i give below ps -ef cmnd with user id as cly to search i'll get the output as below
Code:
dev52:home/k9087cly->ps -ef |grep cly
s0998cly  50228 472666   1 23:10:52  pts/7  0:00 ps -ef
s0998cly 141746 237722   0 22:57:52  pts/6  0:00 ssh isp1.6705
s0998cly 161596 186422   2                  0:00 <defunct>
s0998cly 186422 200216   0 23:08:01  pts/1  0:00 /usr/bin/more -sv
s0998cly 196924 487282   0 23:09:41      -  0:00 sshd: s0998cly@pts/7
s0998cly 200216 470272   0 23:08:01  pts/1  0:00 man grep

in above code i need what is the first column name,second and so on..
Please sugest me the solution.
Thank you

Last edited by Scott; 11-08-2013 at 12:56 AM.. Reason: Added code tags
# 2  
Old 11-08-2013
To fetch the first column:
Code:
ps -ef | grep cly | awk '{print $1}'

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 11-08-2013
Your request is ambiguous. If you include the following line of code in your shell script and you pass the part of the ID you want to match as the 1st argument to that script, the following prints the ps header line and lines with the 1st argument in the 1st field:
Code:
ps -ef | awk -v id="$1" 'NR==1 || $1 ~ id'

If the argument to the script should be an exact name instead of a partial match, use:
Code:
ps -ef | awk -v id="$1" 'NR==1 || $1 == id'

If neither balajesuri nor I guessed at what you want, please show us a sample of the output you want instead of making us guess.
This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 11-08-2013
If you want the column names as headers, grep for sth. that will certainly be in the header, like UID:ps -ef |grep -E "UID|cly"
If that does not satisfy your needs, Don Cragun posted possible solutions.
This User Gave Thanks to RudiC 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

Sorting a column according to the number of names

Hey, So I'm having issues sorting a data set. The data set contains entries as such; # key: sex, time, athlete, athlete's nationality, date, city, country M, 2:30:57.6, Harry Payne, GBR, 1929-07-05, Stamford Bridge, England M, 2:5:42, Khalid Khannouchi, MAR, 1999-10-24, Chicago, USA M,... (1 Reply)
Discussion started by: DNM_UKN
1 Replies

2. UNIX for Dummies Questions & Answers

Listing column names in CSV file

Hi, I have a .csv file that has ~600 columns and thousands of rows. I would like to create a numerical list of the column names (so that I can later easily select the columns I want to extract). The format that I would hope for is something like: 1 "ID" 2 "X" 3 "Y" .. 600 "Z" ... (4 Replies)
Discussion started by: aberg
4 Replies

3. Shell Programming and Scripting

check if the insert statement is using column names

Hi, Input- a file comtaining a procedure or function with various statements in that one of the statement would be insert into table1 (a,b,c) values (1,2,3) ourput required true if insert statement is using column name (a,b,c) else false. Please suggest (8 Replies)
Discussion started by: manasa_vs
8 Replies

4. Shell Programming and Scripting

Transpose field names from column headers to values in one column

Hi All, I'm looking for a script which can transpose field names from column headers to values in one column. for example, the input is: IDa;IDb;IDc;PARAM1;PARAM2;PARAM3; a;b;c;p1val;p2val;p3val; d;e;f;p4val;p5val;p6val; g;h;i;p7val;p8val;p9val; into the output like this: ... (6 Replies)
Discussion started by: popesk
6 Replies

5. Shell Programming and Scripting

How to set column names?

data: For the code below, it extracts info from two files and stores it in outfile. For the ouput file i want to mention some column names like this, So where i can mention in the script to get outfile with code: nawk -F\| 'NR==FNR{n=int($2); a=$2; next}a{print a FS $2}' SC.lis ext.fmt >... (3 Replies)
Discussion started by: Diddy
3 Replies

6. Shell Programming and Scripting

rearrange the column names with comma as column delimiter

Hi, I am new to shell scripting, i have requirement can any one help me out in this regrads, in directory i have file like invoice1.txt, invoice2.txt in each file i have fixed number of columns, 62 in number but they are randomly arranged.like for first file invoice1.txt can have columns... (5 Replies)
Discussion started by: madhav62
5 Replies

7. Shell Programming and Scripting

Change names in a column based on the symbols in another column

If the 4th column has - sign then the names in 3rd column has to change to some user defined names (as shown in output). Thanx input1 1 a aaaaa + 2 b bbbbb + 3 c ccccc + 4 d ddddd + 5 e eeeee + 6 f xxxxx + 8 h hhhhh +... (8 Replies)
Discussion started by: repinementer
8 Replies

8. Shell Programming and Scripting

eleminate repated process names and get second column value

i want shell script who can eliminate those repeated process and get value of top process of second column. Mark with red one only i want other repeated process should be eliminate but how? Help me out guys. oracle 496094 oracle 471572 oracle 471497 oracle 470561 ko9coll 96157... (4 Replies)
Discussion started by: siddiqui
4 Replies

9. Shell Programming and Scripting

Print column names along with values from SQL

Hi, Can anyone tell me how to print the column name anong with the value from the table in shell script e.g #!/bin/ksh var=`sqlplus scott/tiger << -e set heading off feedback off select * from emp; quit; e` echo $var My output should be; ... (5 Replies)
Discussion started by: thana
5 Replies

10. Shell Programming and Scripting

Column names in flat files

Hi all, I want to create column names in a flat file and then load the data through some other application. For example, I have a file with emp.txt and I need column names as eno,ename,sal in the first line. The delimiter here is comma and record delimiter is end of line or unix new line. Could... (1 Reply)
Discussion started by: srivsn
1 Replies
Login or Register to Ask a Question