Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk returns multiple lines

Status
Not open for further replies.

bgs

MIS
May 6, 2002
4
US
How do I get a field out of a ps cmd result that will always fall after a known string?

On each server there is one to n port listeners running.
Each port listener has a name assigned by the local admin. (eg. LIST_1, LIST_BILL, etc)
Each process is running under the same binary. (eg. X)
I am looking for an active process(s) on a server and when I find it the next field will be an assigned port listener name.
Example of the ps result
billy 6758 1 0 Feb 8 ? 4:49 /app/opt/org/product/ver1/bin/X LIST_JOHN -inherit
The ps result line varies in number of return fields.

Here is my program code line that is not working correctly.
ProcessName=$(ps -ef|grep -i X|grep -v grep|awk 'match($0,"X ") {print substr($0,RSTART+RLENGTH)}')
RESULTS
") {print substr($0,RSTART+RLENGTH
LIST_JOHN -inherit
OR sometime the lines are reversed.
I am not sure if I am using RSTART and RLENGTH correctly. I am using RSTART+RLENGTH because this is not always true => awk '{if(NF != 11) print $9; else print $10;}'
Any ideas will greatly help
 
ugly, but......

match($0, "X ") {
print substr($0,RSTART+RLENGTH,index(substr($0,RSTART+RLENGTH), " "))
} vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top