there is a file ,which you can get by command ps aux
in linux.
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 2280 732 ? Ss 08:20 0:00 init [2]
root 327 0.0 0.1 2916 1456 ? Ss 08:20 0:00 udevd --daemon
root 1681 0.0 0.0 2376 800 ? Ss 08:20 0:00 /sbin/rpcbind -w
root 2071 0.0 0.1 27920 1708 ? Sl 08:20 0:00 /usr/sbin/rsyslogd -c5
i want to get the content of last field,such as:
COMMAND
init [2]
udevd --daemon
/sbin/rpcbind -w
/usr/sbin/rsyslogd -c5
when i use , $ awk '{print $11}' test,i get:
COMMAND
init
udevd
/sbin/rpcbind
/usr/sbin/rsyslogd
when i use ,$ awk '{print $12}' test,i get :
[2]
--daemon
-w
-c5
how can i do?
awk '{for(i=1;i<11;i++)$i="";print }'
or you can just do:
awk '{print $11,$12}'
You can loop over the words of the last field and print them:
ps aux | awk '{ for( i=11 ; i <=NF ; i++ ) { printf( "%s ", $i ) } ; print "" }'
If you want to process the command afterwards, you can put it in a variable:
ps aux | awk '{ CMD = "" ; for( i=11 ; i <=NF ; i++ ) { CMD = CMD " " $i } ; sub( /^ /, "", CMD ) ; print CMD }'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With