1.查找awk

# cat /etc/passwd |awk -F ':' 'BEGIN {print "name,shell"} {print $1","$7} END {print "blue,/bin/nosh"}'
name,shell (Begin信息)
root,/bin/bash
daemon,/bin/sh
bin,/bin/sh
sys,/bin/sh
....
blue,/bin/nosh (End信息)
# awk  –F  ’,’  ’{print $1,$2}’   ./test.txt     (-F文件符切割
#源文件     There areorange,apple,mongo,xiangjiao,boluo,yezi 
#输出后文件 There are orangeapple
1、打印文件的第一列(域)                  : awk '{print $1}' filename
2、打印文件的前两列(域) : awk '{print $1,$2}' filename
3、打印完第一列,然后打印第二列 :awk '{print $1 $2}' filename
4、打印文本文件的总行数 : awk 'END{print NR}' filename
5、打印文本第一行 :awk 'NR==1{print}' filename
6、打印文本第二行第一列 :sed -n "2, 1p" filename | awk 'print $1'
7、打印文件的最后一行 :awk 'END{print}' 或 tail -1 file
#awk -F: '/root/' /etc/passwd   (搜索/etc/passwd有root关键字的所有行)
root:x:::root:/root:/bin/bash

2.查找 grep

[root@localhost ~]grep  "logread"  /etc   -nr
#在/etc文件下查找logread关键字,-n :顺便输出行号,-r 递归处理,将指定目录下的所有文件及子目录一并处理

grep: /etc/fstab: No such file or directory
/etc/init.d/fhlog:8:PROG=/sbin/logread
/etc/init.d/fhlog:10:PID_FILE="/var/run/logread.fhlog.pid"
grep: /etc/ppp/resolv.conf: No such file or directory
/etc/rc.d/K89fhlog:8:PROG=/sbin/logread
/etc/rc.d/K89fhlog:10:PID_FILE="/var/run/logread.fhlog.pid"
/etc/rc.d/S21fhlog:8:PROG=/sbin/logread
/etc/rc.d/S21fhlog:10:PID_FILE="/var/run/logread.fhlog.pid"
[root@localhost ~]tail -f 20190625_access.log | grep  "error" --color
#实时查找日志中error关键字并显示颜色

最新文章

  1. CoolPlist 帧动画自动生成工具
  2. 终于开始用github了
  3. 多线程java的concurrent用法详解(转载)
  4. List<String[]>
  5. Ant执行Jmeter工程模版
  6. RequestMethod 相关
  7. JavaScript中的getBoundingClientRect()方法
  8. cocos2d-x 在mac下执行 demo
  9. template might not exist or might not be accessible by any of the configured Template Resolvers
  10. 洛谷 P2762 太空飞行计划问题 P3410 拍照【最大权闭合子图】题解+代码
  11. ArcPy 重命名拷贝删除图层
  12. app.config的坑
  13. 【Api】easy-mock在线api
  14. Linux ,Ubuntu 分区建议大小
  15. 【Java基础】16、小数的浮点型和定点型
  16. sql server 的Maintenance Plans(维护计划)详解
  17. First Date (hnoj12952)日期计算
  18. nGrinder的安装与使用
  19. python生成器(转)
  20. C++字符串string类常用操作详解(一)【初始化、遍历、连接】

热门文章

  1. 小程序-demo:小程序示例-page/common
  2. bzoj 4236: JOIOJI【前缀和+map】
  3. 洛谷P4315 月下“毛景树”(树剖+线段树)
  4. 比特币搬砖对冲策略Python源码
  5. 在代码里更新autolayout布局
  6. python网络爬虫之四简单爬取豆瓣图书项目
  7. poj 3159 Candies dijkstra + queue
  8. 2017 JUST Programming Contest 3.0 K. Malek and Summer Semester
  9. ACM_Encoding
  10. magento getMessage 不显示或者显示html标签解决方案