多个分隔符:
[root@hqy oldboy]# awk -F "[ :]+" '{print $4,$6,$8}' oldboy.txt
10.10.9.201 10.10.9.255 255.255.255.0
打印10-20行
[root@hqy oldboy]# awk 'NR>9 && NR<21 ' passwd | cat -n
1 uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
2 operator:x:11:0:operator:/root:/sbin/nologin
3 games:x:12:100:games:/usr/games:/sbin/nologin
4 gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
5 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
6 nobody:x:99:99:Nobody:/:/sbin/nologin
7 dbus:x:81:81:System message bus:/:/sbin/nologin
8 vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
9 rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin
10 abrt:x:173:173::/etc/abrt:/sbin/nologin
11 rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
修改当前目录下所有的.txt文件内的root 修改成heqiuyu
[root@hqy oldboy]# find . -type f -name "*.txt" | xargs sed -i 's#root#heqiuyu#g'
[root@hqy oldboy]# cat passwd.txt
heqiuyu:x:0:0:heqiuyu:/heqiuyu:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/heqiuyu:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
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
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
saslauth:x:499:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
oprofile:x:16:16:Special user account to be used by OProfile:/home/oprofile:/sbin/nologin
heqiuyu:x:500:500::/home/heqiuyu:/bin/bash
网友评论