Avoid file creation in a script...achive same result

Guys
following lines help me in getting numbers from PID column ,to be thrown into first column of a CSV file.

COLUMNS=2047 /usr/bin/ps -eo pid,ppid,uid,user,args | grep -v "PID" > /tmp/masterPID.txt
cat /tmp/masterPID.txt|while read line
do
PID=`echo $line|awk '{print $1}'`
echo "$PID"
done

Using following lines,i am able to print PPID column ,corrsponding to PID found above. [ Do not bother about "@@Host Processes.PID@@".My tool allows me to pass variables from column to column ]

PID="@@Host Processes.PID@@"
cat /tmp/masterPID.txt|while read line
do
temp=`echo $line|awk '{print $1}'`
if [ $temp = $PID ]
then
PPID=`echo $line|awk '{print $2}'`
echo "$PPID"
fi
done

My problem is ,even though i am able to get both columns in my CSV file,this code is doing a lot of I/O because of static file creation on box.I am myself against using a static file.

Is there a way i can achive the same without creating any file?

Regards
Abhi

try:

PID="@@Host Processes.PID@@"
awk -v pid="$PID" '$1==pid {print $2}' /tmp/masterPID.txt

thanks jim,

let me re-phrase my problem..

i do not want "/tmp/masterPID.txt" file to be created in the first place...

i need to iterate following command's o/p to get all five columns...

"COLUMNS=2047 /usr/bin/ps -eo pid,ppid,uid,user,args"

Regards
Abhi

I simplified a bit but does this not work for you?

COLUMNS=2047 ps -eo pid,ppid,uid,user,args | grep -v "PID" | while read line
do
 echo "$line"
done

Well ...thanks for the suggestion guys!!

I wrote like this:

PID:

COLUMNS=2047 /usr/bin/ps -eo pid,ppid,uid,user,args | grep -v "PID" |while read line
do
PID=`echo $line|awk '{print $1}'`
echo "$PID"
done

PPID:

PID="@@Host Processes.PID@@"
COLUMNS=2047 /usr/bin/ps -eo pid,ppid,uid,user,args|grep -v "PID" |while read line
do
temp=`echo $line|awk '{print $1}'`
if [ $temp = $PID ]
then
PPID=`echo $line|awk '{print $2}'`
echo "$PPID"
fi
done

I am getting desired columns but there is a small issue here.Some processes shut down or hibernate for some time.

I am losing PPID,UID,USER,ARGS columns for some PIDs.

This is how it looks :

Host Name	PID	PPID	UID	USER	COMMAND

<hostname>	323830				
<hostname>	307638				
<hostname>	360788				
<hostname>	106618	1	0	root	/usr/lib/errdemon
<hostname>	110744	123026	0	root	/usr/sbin/dpid2
<hostname>	114688	123026	0	root	/usr/sbin/syslogd
<hostname>	118976	123026	0	root	sendmail:

Reason probably is i am passing whole command again as an input to 'while' loop.

Earlier when i was putting it in a file,it was a snapshot on which iteration was happening.

Now i have two questions:

1.How can above issue be handled?

2.Is there any way looping can be avoided ? [ I am personally of the opinion that loop is must if i have to catch whole row ].

Regards
Abhi