文字處理三劍客命令

2022-05-15 15:37:31 字數 2478 閱讀 4362

一、sed 

一 、sed

正則定位

sed '

/^egon$/p

' a.txt #這一行只能有egon這個字元

[root@localhost ~]#

sed '1,/egon/p' bug #列印第一行首次匹配到/egon/的行

p           列印

s///gi      替換

sed '

1,3s/egon/egon/'檔案

sed

'/^egon/s/egon/egon/

' 檔案

[root@localhost ~]# sed '1,3s/egon/ddd/g' bug      #替換全部

[root@localhost ~]# sed '1,3s/egon/ddd/i' bug         #不區分大小寫

[root@localhost ~]# cat bug | sed 's/egon/nnn/'

[root@localhost ~]# head -3 bug |sed 's/egon/mmm/'      

[root@localhost ~]# ifconfig | sed 's/ens33/etho/' #替換網絡卡名

二 、awk

awk -f: '

nr == 3

' /etc/passwd

awk -f: '

nr >= 3 && nr <=5

' /etc/passwd

awk -f: '

nr <= 3 || nr >=8

'test.txt

awk -f: '

nr == 3 || nr ==5 || nr==7

' test.txt

[root@localhost ~]#

head -10 /etc/passwd >1.txt

[root@localhost ~]#

awk -f: 'nr<=3 || nr <=8' 1.txt

[root@localhost ~]#

awk -f: 'nr>=3 && nr<=5' 1.txt

[root@localhost ~]#

awk -f' ' '' 2

[root@localhost ~]#

ifconfig ens33 | awk 'nr == 2'

inet 192.168.12.239 netmask 255.255.255.0 broadcast 192.168.12.255

[root@localhost ~]#

ifconfig ens33 | awk 'nr == 2'

192.168.12.239

[root@localhost ~]#

ifconfig ens33 | awk 'nr == 2' | awk -f. ''

192[root@localhost ~]#

awk -f: '' 1.txt #這個檔案以:分割,然後列印出每一行被切了多少的數量

三 、grep

[root@localhost ~]#

ps aux | grep '[s]sh'

[root@web01 ~]#

ps aux |grep 'vim'

root 9825 0.0 0.5 151692 5212 pts/1 s+ 12:05 0:00vim a.txt

root 10190 0.0 0.0 112724 988 pts/0 r+ 12:30 0:00 grep --color=auto vim

[root@web01 ~]#

ps aux |grep '[v]im'

root 9825 0.0 0.5 151692 5212 pts/1 s+ 12:05 0:00vim a.txt

[root@web01 ~]#

kill -9 9825

快捷鍵:ctrl+alt+delete

c:\users\oldboy>taskkill /f /pid 12080成功: 已終止 pid 為 12080的程序。

c:\users\oldboy>tasklist | findstr "

wechat.exe

"wechat.exe 11412 console 1 127,836k

c:\users\oldboy>taskkill /f /pid 11412成功: 已終止 pid 為 11412 的程序。

文字處理三劍客

文字處理三劍客 劍客一 grep 作用 行 過濾 用法 grep 正規表示式 檔案 路徑 grep e 擴充套件類正規表示式 檔案 路徑 劍客二 sed 用法 sed 選項 位址定位sed命令 檔案 路徑 sed 選項 正規表示式 sed命令 檔案 路徑 sed 選項 位址定位 正規表示式 sed命...

Linux文字處理三劍客

grep 作用 文字搜尋工具,根據使用者指定的 模式對目標檔案逐步進行匹配檢查,列印匹配到的行 grep root etc passwd grep命令選項 grep user etc passwd v 顯示不被pattern 匹配的行 e 僅顯示匹配到的字串 grep user etc passwd...

linux文字處理三劍客

常用引數 v 顯示不能夠被匹配到的行 i 忽略大小寫字元 o 僅顯示匹配到的字串 q 靜默模式,不輸出任何資訊 a 後 行 b 前 行 c 前後各 行 e 使用ere,相當於egrep常用引數 n 只列印模式匹配的行 e 直接在命令列模式上進行sed動作編輯,此為預設選項 f 將sed的動作寫在乙個...