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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

merge two lines - parent+child processes

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
PL
hello,

on the output of:
ps -uauser -e -o pid,ppid,args

I can extract lines like (it is example):
17531 11234 bcommand options .....
17803 17802 /bin/bash ascript .....
17871 17803 acommand options .....
11234 17755 /bin/bash bscript .....
etc...

and I want to search for pairs of processes (parent+child, so lines for which pid in one line == ppid in second one) and join them in one line to get finally output - example basing on above input:
17803 17802 /bin/bash ascript ..... acommand options .....
11234 17755 /bin/bash bscript ..... bcommand options .....

thank you for any hint





 
See if this awk command will work for you:
Code:
awk '{c[$2]++;l=$0;gsub("^[0-9]+ *[0-9]+ *","",l);pid[$1]=l;ppid[$2]=(ppid[$2]?ppid[$2] " " l : l)}END{for(i in ppid) if (i in pid) {pid[i] = pid[i]" "ppid[i];print i, pid[i]}}' file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top