grep 或 egrep 或awk 过滤两个或多个关键词
[root@hch ~]# grep -E '123|abc' test.txt
123lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail1234:/var/spool/mail:/sbin/nologin
games:x:12:100:games123:/usr/games:/sbin/nologin
ftp:x:14:50:FTP Userabc:/var/ftp:/sbin/nologin
systemd-network:x:192:abc192:systemd Network Management:/:/sbin/nologin
postfix:x:89:89::/var/spoabcol/postfix:/sbin/nologin
[root@hch ~]# egrep '123|abc' test.txt
123lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail1234:/var/spool/mail:/sbin/nologin
games:x:12:100:games123:/usr/games:/sbin/nologin
ftp:x:14:50:FTP Userabc:/var/ftp:/sbin/nologin
systemd-network:x:192:abc192:systemd Network Management:/:/sbin/nologin
postfix:x:89:89::/var/spoabcol/postfix:/sbin/nologin
[root@hch ~]# awk '/123|abc/' test.txt
123lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail1234:/var/spool/mail:/sbin/nologin
games:x:12:100:games123:/usr/games:/sbin/nologin
ftp:x:14:50:FTP Userabc:/var/ftp:/sbin/nologin
systemd-network:x:192:abc192:systemd Network Management:/:/sbin/nologin
postfix:x:89:89::/var/spoabcol/postfix:/sbin/nologin
用awk编写生成以下结构文件的程序。( 最后列使用现在的时间,时间格式为YYYYMMDDHHMISS) 各列的值应如下所示,每增加一行便加1,共500万行。
1,1,0000000001,0000000001,0000000001,0000000001,0000000001,0000000001,2005100110101
2,2,0000000002,0000000002,0000000002,0000000002,0000000002,0000000002,2005100110101
[root@hch ~]# awk 'BEGIN{for(i=1;i<=10;i++)printf("%d,%d,%010d,%010d,%010d,%010d,%010d,%010d,%d\n",i,i,i,i,i,i,i,i,strftime("%Y%m%d%H%M"))}'
1,1,0000000001,0000000001,0000000001,0000000001,0000000001,0000000001,201712311204
2,2,0000000002,0000000002,0000000002,0000000002,0000000002,0000000002,201712311204
3,3,0000000003,0000000003,0000000003,0000000003,0000000003,0000000003,201712311204
4,4,0000000004,0000000004,0000000004,0000000004,0000000004,0000000004,201712311204
5,5,0000000005,0000000005,0000000005,0000000005,0000000005,0000000005,201712311204
awk用print打印单引号
[root@hch ~]# awk '{print "\""}' test.txt
"
"
"
"
把两个文件中相同的行合并成一行
[root@hch ~]# paste a.txt b.txt
1 2 3 3 2 1
4 5 6 6 5 4
a b c c b a
如果,你想在两个文件连接处用一个指定的字符连接,还可以用-d来指定