0

I have the following long one liner which essentially provides a list of PIDs with a '|' delim character

echo $(lsof -p $(pgrep -f dosemu | tr '\012' ,) | grep '/media/datadrv' | awk '{print $2" - " $9}' | grep 'DBASE1.RES' | awk '{print $1}') | sed 's/\s\+/|/g'

this output something similar to 19066|19500

What I want to do is use this to feed into the pstree command using egrep.

for example the following command gives me what i need

pstree -p | egrep '19066|19500'

What I cant figure out is how to feed the results of the first command into the second.

Update Thanks to Goro's answer the complete one liner was :-

pstree -p | egrep $(echo $(lsof -p $(pgrep -f dosemu | tr '\012' ,) | grep '/media/datadrv' | awk '{print $2" - " $9}' | grep 'DBASE1.RES' | awk '{print $1}') | sed 's/\s\+/|/g')
l0ckm4
  • 103
  • 4
  • Hellow @l0ckm4. If I understand correctly, you would like to feed `19066|19500` to the command `pstree -p` I mean, you would like to feed the numbers in the flag `-p` correct? –  Sep 26 '18 at 10:42

1 Answers1

1

You can give the linear a variable name

var=$(echo $(lsof -p $(pgrep -f dosemu | tr '\012' ,) | grep '/media/datadrv' | awk '{print $2" - " $9}' | grep 'DBASE1.RES' | awk '{print $1}') | sed 's/\s\+/|/g')

Then feed var into pstree as follows:

pstree -p $var

If you would like to feed one of the numbers 19066|19500, you can use sed to convert | to tab \t, then awk the number of interest as follows:

first_number=$(echo ${var} | sed 's/|/\t/g' | awk '{print $1}' )
19066
 pstree -p ${first_number}