Re: filter out a field (270 Views)
Reply
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 1 of 7 (270 Views)
Accepted Solution

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
Please use plain text.
Honored Contributor
Victor Fridyev
Posts: 937
Registered: ‎07-01-1998
Message 2 of 7 (270 Views)

Re: filter out a field

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

HTH
Entities are not to be multiplied beyond necessity - RTFM
Please use plain text.
Honored Contributor
Leif Halvarsson_2
Posts: 6,682
Registered: ‎01-09-2002
Message 3 of 7 (270 Views)

Re: filter out a field

Hi,

Or, try the following:

proc=$(command |awk '{print $2; getline}')
Please use plain text.
Honored Contributor
Hein van den Heuvel
Posts: 6,585
Registered: ‎05-19-2003
Message 4 of 7 (270 Views)

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.

Please use plain text.
Honored Contributor
Hein van den Heuvel
Posts: 6,585
Registered: ‎05-19-2003
Message 5 of 7 (270 Views)

Re: filter out a field

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

Please use plain text.
Honored Contributor
H.Merijn Brand (procura
Posts: 6,185
Registered: ‎10-13-1997
Message 6 of 7 (270 Views)

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
Please use plain text.
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 7 of 7 (270 Views)

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
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation