Showing results for 
Search instead for 
Do you mean 

filter out a field

SOLVED
Go to Solution
Super Advisor Super Advisor

filter out a field

Hello,

I run a command to see the status of a process,

this is displayed on tow lines and I want to add the started string to a variable

ie

proc=$(command |awk {'print $2})

however print $2 displays status on the first line and started on the second - how do I pass started into $proc?

thanks
hello
6 REPLIES
Honored Contributor Honored Contributor

Re: filter out a field

Hi,
proc=$(command |awk 'NR>1{print $2}')

HTH
Entities are not to be multiplied beyond necessity - RTFM
Honored Contributor

Re: filter out a field

Hi,

Or, try the following:

proc=$(command |awk '{print $2; getline}')
Honored Contributor Honored Contributor

Re: filter out a field

>> I run a command to see the status of a process,

Are you talking about 'ps' with some options?
In Tru64, contrary to say hpux, you can specifically request any and all indivudual fields with a '-o'. They may reduce the need for post processing.

What problem are you really trying to solve?
That is, what else is the script doing after grabbing thoze fields? We may be able to help you better with a little more awk or perl scripting.

If you need further help, be sure to re-reply with (a text attachment of)
- the command currently used to gather info
- A sample output of that command
- a sample of the desired final output based on the above.

Cheers,

Hein.

Honored Contributor Honored Contributor

Re: filter out a field

ooops, my mistake, I thought I was in the Tru64 forum while composing the prior reply. Hein.

Honored Contributor Honored Contributor

Re: filter out a field

Hein, you can achieve the same on HPUX with UNIX95 set to a single space.


# a5:/u/usr/merijn 101 > ps
PID TTY TIME COMMAND
19657 pts/0 0:00 ps
19577 pts/0 0:00 tcsh
a5:/u/usr/merijn 102 > env UNIX95=" " ps -o pid
PID
19577
19836
a5:/u/usr/merijn 103 > env UNIX95=" " ps -o pid,tty
PID TT
19577 pts/0
19837 pts/0
a5:/u/usr/merijn 104 > env UNIX95=" " ps -o tty,command
ps: command is not a valid field name
Exit 1
a5:/u/usr/merijn 105 > env UNIX95=" " ps -o tty,cmd
ps: cmd is not a valid field name
Exit 1
a5:/u/usr/merijn 106 > env UNIX95=" " ps -o tty,time
TT TIME
pts/0 00:00
pts/0 00:00
a5:/u/usr/merijn 107 >

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Highlighted
Super Advisor Super Advisor

Re: filter out a field

Thanx all for your replies,

Victor your solution still display's both lines

Hein, thanks for your your advise and input however I am learning scripting and would prefer to read and educate myself rather than have half scripts etc supplied

Leif - thanks a million, I have used your command.
hello