-5

If this is the input to a file

testabc     Perf Agent data collector                        (26748)  Running
midaemon    Measurement Interface daemon                     (26565)  Running
ttd         ARM registration daemon                          (1779)   Running
alarm        Alarm generator                                 (26764)  Running
coda         Performance Core                 COREXT                Stopped
opcacta      Action Agent                    AGENT,EA     (26635)  Running
opcle        Logfile Encapsulator            AGENT,EA     (26613)  Running
opcmona      Monitor Agent                   AGENT,EA     (26620)  Running
opcmsga      Message Agent                   AGENT,EA     (26597)  Running
opcmsgi      Message Interceptor             AGENT,EA     (26641)  Running
abcdccb     Communication Broker             CORE         (26571)  Running
ovcd         Control                          CORE         (26567)  Running
ovconfd      Config and Deploy                COREXT       (26588)  Running
Message Agent is not buffering.

Any help is much appreciated. Only "awk" needs to be used not even nawk as it is not installed in most systems.

4 Answers4

3

try this;

 awk '{print $NF}' <YourFile>

NF: gives you the total number of fields in a record

Mustafa DOGRU
  • 3,994
  • 1
  • 16
  • 24
0

If you have rev installed, you can just use it and process the first column, then rev back:

rev < file | awk '{print $1}' | rev

You can also use cut instead of awk:

rev < file | cut -d' ' -f1 | rev

That's what I usually do, it's surprisingly fast.

choroba
  • 231,213
  • 25
  • 204
  • 289
0
awk -F' ' '{print $NF}'

-F - delimiter(whitespace is the default)
$NF - last column, $(NF-1), last but one column and so on
anudeep
  • 415
  • 6
  • 19
  • Thanks Anudeep. Could you help me with the command if i want to use multiple delimiters like () \t and ' ' only with awk – Su_scriptingbee Aug 16 '16 at 14:32
  • You can specify like awk -F '[:;/=]' '{print $0}' delimiters above are ":, ;, /, =" – anudeep Aug 17 '16 at 09:23
  • am getting the below error while using multiple delimiters. awk -F '[:;/=]' '{print $0}' test_file awk: syntax error near line 1 awk: bailing out near line 1 OS is solaris. – Su_scriptingbee Aug 17 '16 at 16:47
0

AWK:

awk '$0=$NF""' file

Replace the record $0 with the last field $NF and print.

James Brown
  • 36,089
  • 7
  • 43
  • 59