【原】简单shell练习(二)
2024-10-09 03:07:52
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关键字并显示颜色
最新文章
- CoolPlist 帧动画自动生成工具
- 终于开始用github了
- 多线程java的concurrent用法详解(转载)
- List<;String[]>;
- Ant执行Jmeter工程模版
- RequestMethod 相关
- JavaScript中的getBoundingClientRect()方法
- cocos2d-x 在mac下执行 demo
- template might not exist or might not be accessible by any of the configured Template Resolvers
- 洛谷 P2762 太空飞行计划问题 P3410 拍照【最大权闭合子图】题解+代码
- ArcPy 重命名拷贝删除图层
- app.config的坑
- 【Api】easy-mock在线api
- Linux ,Ubuntu 分区建议大小
- 【Java基础】16、小数的浮点型和定点型
- sql server 的Maintenance Plans(维护计划)详解
- First Date (hnoj12952)日期计算
- nGrinder的安装与使用
- python生成器(转)
- C++字符串string类常用操作详解(一)【初始化、遍历、连接】
热门文章
- 小程序-demo:小程序示例-page/common
- bzoj 4236: JOIOJI【前缀和+map】
- 洛谷P4315 月下“毛景树”(树剖+线段树)
- 比特币搬砖对冲策略Python源码
- 在代码里更新autolayout布局
- python网络爬虫之四简单爬取豆瓣图书项目
- poj 3159 Candies dijkstra + queue
- 2017 JUST Programming Contest 3.0 K. Malek and Summer Semester
- ACM_Encoding
- magento getMessage 不显示或者显示html标签解决方案