awk2
9252 단어 awk
[root@gz1 ~]# awk -F ':' '$1=="mysql"' 1.txt
mysql:x:500:500::/home/mysql:/sbin/nologin
[root@gz1 ~]# awk -F ':' '$3>=500' 1.txt
nfsnobody:x:65534:65a534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
mysql:x:500:500::/home/mysql:/sbin/nologin
[root@gz1 ~]# awk -F ':' '$3<=500' 1.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
drooaemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:riox:3:4:adm:/var/adm:/sbin/nologooin
lp:x:4:r_o7:lp:/var/spool/lpd:/sbin/nolooogin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdooown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nolooogin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
ogames:x:12:100:games:/usr/games:/sbin/nologooin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
vcsoa:x:69:69:virtual aconsole memory owner:/dev:/sbin/nologin
rpc:x:32:32:Rpcbind Da*emon:/var/cache/rpcbind:/sbin/nologin
sasloauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/sp.oool/postfix:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
rpcuser:x:29:29:RPCr Service User:/var/lib/nfs:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
mysql:x:500:500::/home/mysql:/sbin/nologin
888888888888888888888888888888888888888888888888
&&&&&&&&&&&&&********************^^^^^^&^6
'''''''''''''''''''
[root@gz1 ~]# awk -F ':' '$7!="/sbin/nologin"' 1.txt
root:x:0:0:root:/root:/bin/bash
adm:riox:3:4:adm:/var/adm:/sbin/nologooin
lp:x:4:r_o7:lp:/var/spool/lpd:/sbin/nolooogin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdooown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nolooogin
ogames:x:12:100:games:/usr/games:/sbin/nologooin
888888888888888888888888888888888888888888888888
&&&&&&&&&&&&&********************^^^^^^&^6
'''''''''''''''''''
awk OFS
[root@gz1 ~]# awk -F ':' 'OFS=":"; $3=$4' 1.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
drooaemon:x:2:2:daemon:/sbin:/sbin/nologin
drooaemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:riox:3:4:adm:/var/adm:/sbin/nologooin
adm:riox:4:4:adm:/var/adm:/sbin/nologooin
lp:x:4:r_o7:lp:/var/spool/lpd:/sbin/nolooogin
lp:x:r_o7:r_o7:lp:/var/spool/lpd:/sbin/nolooogin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdooown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nolooogin
mail:x:12:12:mail:/var/spool/mail:/sbin/nolooogin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
uucp:x:14:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
ogames:x:12:100:games:/usr/games:/sbin/nologooin
ogames:x:100:100:games:/usr/games:/sbin/nologooin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
gopher:x:30:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
ftp:x:50:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
vcsoa:x:69:69:virtual aconsole memory owner:/dev:/sbin/nologin
vcsoa:x:69:69:virtual aconsole memory owner:/dev:/sbin/nologin
rpc:x:32:32:Rpcbind Da*emon:/var/cache/rpcbind:/sbin/nologin
rpc:x:32:32:Rpcbind Da*emon:/var/cache/rpcbind:/sbin/nologin
sasloauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
sasloauth:x:76:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/sp.oool/postfix:/sbin/nologin
postfix:x:89:89::/var/sp.oool/postfix:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
rpcuser:x:29:29:RPCr Service User:/var/lib/nfs:/sbin/nologin
rpcuser:x:29:29:RPCr Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65a534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65a534:65a534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
mysql:x:500:500::/home/mysql:/sbin/nologin
mysql:x:500:500::/home/mysql:/sbin/nologin
888888888888888888888888888888888888888888888888
&&&&&&&&&&&&&********************^^^^^^&^6
'''''''''''''''''''
awk의 NR 행
10보다 작은 아홉 줄을 인쇄해 내다
[root@gz1 ~]# awk -F ':' 'NR<10' 1.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
drooaemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:riox:3:4:adm:/var/adm:/sbin/nologooin
lp:x:4:r_o7:lp:/var/spool/lpd:/sbin/nolooogin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdooown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nolooogin
열 줄 이상의 줄을 인쇄해 내다
[root@gz1 ~]# awk -F ':' 'NR>10' 1.txt
operator:x:11:0:operator:/root:/sbin/nologin
ogames:x:12:100:games:/usr/games:/sbin/nologooin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
vcsoa:x:69:69:virtual aconsole memory owner:/dev:/sbin/nologin
rpc:x:32:32:Rpcbind Da*emon:/var/cache/rpcbind:/sbin/nologin
sasloauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/sp.oool/postfix:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
rpcuser:x:29:29:RPCr Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65a534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
mysql:x:500:500::/home/mysql:/sbin/nologin
888888888888888888888888888888888888888888888888
&&&&&&&&&&&&&********************^^^^^^&^6
'''''''''''''''''''
10을 인쇄하다
[root@gz1 ~]# awk -F ':' 'NR==10' 1.txt
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
지정된 세그먼트만 인쇄하기
[root@gz1 ~]# awk -F ':' 'NR==10{print $1,$7}' 1.txt
uucp /sbin/nologin
awk NF 세그먼트
세그먼트 보기
[root@gz1 ~]# awk -F ':' '{print NF}' 1.txt
7
7
7
7
7
7
7
7
7
7
0
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
1
1
1
awk의 수학 연산
[root@gz1 ~]# awk -F ':' 'OFS=":" {$7=$3+$4; print $0}' 1.txt
root:x:0:0:root:/root:0
bin:x:1:1:bin:/bin:2
drooaemon:x:2:2:daemon:/sbin:4
adm:riox:3:4:adm:/var/adm:7
lp:x:4:r_o7:lp:/var/spool/lpd:4
sync:x:5:0:sync:/sbin:5
shutdown:x:6:0:shutdown:/sbin:6
halt:x:7:0:halt:/sbin:7
mail:x:8:12:mail:/var/spool/mail:20
uucp:x:10:14:uucp:/var/spool/uucp:24
::::::0
operator:x:11:0:operator:/root:11
ogames:x:12:100:games:/usr/games:112
gopher:x:13:30:gopher:/var/gopher:43
ftp:x:14:50:FTP User:/var/ftp:64
nobody:x:99:99:Nobody:/:198
dbus:x:81:81:System message bus:/:162
vcsoa:x:69:69:virtual aconsole memory owner:/dev:138
rpc:x:32:32:Rpcbind Da*emon:/var/cache/rpcbind:64
sasloauth:x:499:76:Saslauthd user:/var/empty/saslauth:575
postfix:x:89:89::/var/sp.oool/postfix:178
haldaemon:x:68:68:HAL daemon:/:136
rpcuser:x:29:29:RPCr Service User:/var/lib/nfs:58
nfsnobody:x:65534:65a534:Anonymous NFS User:/var/lib/nfs:65599
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:148
mysql:x:500:500::/home/mysql:1000
888888888888888888888888888888888888888888888888::::::0
&&&&&&&&&&&&&********************^^^^^^&^6::::::0
'''''''''''''''''''::::::0
그중의 일부 단락만
[root@gz1 ~]# awk -F ':' 'OFS=":" {$7=$3+$4; print $1,$3}' 1.txt
root:0
bin:1
drooaemon:2
adm:3
lp:4
sync:5
shutdown:6
halt:7
mail:8
uucp:10
:
operator:11
ogames:12
gopher:13
ftp:14
nobody:99
dbus:81
vcsoa:69
rpc:32
sasloauth:499
postfix:89
haldaemon:68
rpcuser:29
nfsnobody:65534
sshd:74
mysql:500
888888888888888888888888888888888888888888888888:
&&&&&&&&&&&&&********************^^^^^^&^6:
''''''''''''''''''':
모든 세 번째 단락을 더해서 화해를 구하다
[root@gz1 ~]# awk -F ':' '{(sum=sum+$3)}; END {print sum}' 1.txt
67170
`
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[fish] awk의 스크립트 부분을 히스토리에서 보완awk 의 사용법이 우울한 기억으로, 그렇다면 어떻게 할까? 다시 검색하는 것이 많았기 때문에 어떻게든하고 싶다. peco 그리고 과거의 awk 이력을 찾는 것도 있지만, fish 그래서 보완으로 해결할 수 있으면 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.