Linux命令

出自 qingwei personal wiki
於 2017年12月1日 (五) 09:17 由 Qingwei (對話 | 貢獻) 所做的修訂 (创建页面,内容为“== awk == === 打印第一行第二列 === <source lang="shell"> ps -ef | grep sshd | head -n1 | awk {'print $2'} # example [qingwyan@localhost smartphy114]$ ps -ef…”)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
前往: 導覽搜尋

awk

打印第一行第二列

ps -ef | grep sshd | head -n1 | awk {'print $2'}
# example
[qingwyan@localhost smartphy114]$ ps -ef | grep sshd
root      1405     1  0 Nov23 ?        00:00:00 /usr/sbin/sshd -D
root     13092  1405  0 19:49 ?        00:00:00 sshd: qingwyan [priv]
qingwyan 13108 13092  0 19:49 ?        00:00:00 sshd: qingwyan@notty
qingwyan 16602 32280  0 21:07 pts/5    00:00:00 grep --color=auto sshd
root     20010  1405  0 Nov28 ?        00:00:02 sshd: root@pts/19

[qingwyan@localhost smartphy114]$ ps -ef | grep sshd | head -n1 | awk {'print $2'}
1405