fgrep “09-MAY-2022” listener.logabc |fgrep “establish” | awk ‘{ print $1" " $2 }’ | awk -F: ‘{ print $1 }’ | sort | uniq -c
1.
fgrep “09-MAY-2022” listener.logabc
截取涵盖时间"09-MAY-2022"的部分
2.
fgrep “09-MAY-2022” listener.logabc |fgrep “establish”
截取同时满足时间"09-MAY-2022"和带有"establish"
3.
fgrep “09-MAY-2022” listener.logabc |fgrep “establish” | awk ‘{ print $1" " $2 }’
满足上面条件后截取第一列+空格+第二列
4.
fgrep “09-MAY-2022” listener.logabc |fgrep “establish” | awk ‘{ print $1" " $2 }’ | awk -F: ‘{ print $1 }’
满足上面条件后,截取’:'为分界的第一列
fgrep “09-MAY-2022” listener.logabc |fgrep “establish” | awk ‘{ print $1" " $2 }’ | awk -F: ‘{ print $1":"$2}’
分割1,2列中间加个":"
5.
fgrep “09-MAY-2022” listener.logabc |fgrep “establish” | awk ‘{ print $1" " $2 }’ | awk -F: ‘{ print $1 }’ | sort
排序
6.
fgrep “09-MAY-2022” listener.logabc |fgrep “establish” | awk ‘{ print $1" " $2 }’ | awk -F: ‘{ print $1 }’ | sort | uniq -c
记录数量
cat listener.logabc |sed -n ‘/09-MAY-2022 05:24:35/,/09-MAY-2022 04:07:17/p’ | sed ‘s/*.*HOST=/ /g;s/).HOST=/ /g;s/).$//g’ | awk ‘{print $3}’ | sort -rn | uniq -c | sort -k 1
2.注意:筛选的时间必须是真实日志里存在的。正常是前面小,后面大,下图相反是因为人为修改了时间。如果
cat listener.logabc |sed -n ‘/09-MAY-2022 05:24:35/,/09-MAY-2022 04:07:17/p’
3.
cat listener.logabc |sed -n ‘/09-MAY-2022 05:24:35/,/09-MAY-2022 04:07:17/p’ | sed ‘s/*.*HOST=/ /g;s/).HOST=/ /g;s/).$//g’
sed ‘s/*.*HOST=/ /g;s/).HOST=/ /g;s/).$//g’
拆解(s代表替换,g表示直接替换,g换个3就是重复的第三个//中的值替换。sed ‘s/abc/ /3;’ 意思:第三个abc替换成空格。代表所有的前面需要加.也就是. *只代表*这个字符。如果sed有多个,可以用;隔开。$代表最后)
sed
s/*.*HOST=/ /g;
翻译
*字符到HOST=中间替换成空格
cat listener.logabc |sed -n ‘/09-MAY-2022 05:24:35/,/09-MAY-2022 04:07:17/p’ | sed ‘s/*.*HOST=/ /g’
s/).*HOST=/ /g;
翻译
)到HOST=中间替换成空格
cat listener.logabc |sed -n ‘/09-MAY-2022 05:24:35/,/09-MAY-2022 04:07:17/p’ | sed ‘s/*.*HOST=/ /g;s/).*HOST=/ /g’
s/).* / / g ∗ ∗ 翻译 ) 到最后( //g **翻译 )到最后( //g∗∗翻译)到最后()中间替换成空值**
cat listener.logabc |sed -n ‘/09-MAY-2022 05:24:35/,/09-MAY-2022 04:07:17/p’ | sed ‘s/*.*HOST=/ /g;s/).HOST=/ /g;s/).$//g’
4.
cat listener.logabc |sed -n ‘/09-MAY-2022 05:24:35/,/09-MAY-2022 04:07:17/p’ | sed ‘s/*.*HOST=/ /g;s/).HOST=/ /g;s/).$//g’ | awk ‘{print $3}’
输出第三列
5.排序
cat listener.logabc |sed -n ‘/09-MAY-2022 05:24:35/,/09-MAY-2022 04:07:17/p’ | sed ‘s/*.*HOST=/ /g;s/).HOST=/ /g;s/).$//g’ | awk ‘{print $3}’ | sort -rn
sort -rn代表数字颠倒排序
6.
cat listener.logabc |sed -n ‘/09-MAY-2022 05:24:35/,/09-MAY-2022 04:07:17/p’ | sed ‘s/*.*HOST=/ /g;s/).HOST=/ /g;s/).$//g’ | awk ‘{print $3}’ | sort -rn | uniq -c
uniq -c记录数量
7.
cat listener.logabc |sed -n ‘/09-MAY-2022 05:24:35/,/09-MAY-2022 04:07:17/p’ | sed ‘s/*.*HOST=/ /g;s/).HOST=/ /g;s/).$//g’ | awk ‘{print $3}’ | sort -rn | uniq -c | sort -k 1