文件名称: CloudPayment.log

搜索内容:1805 或 1905 

 输出文件: out.log

1、满足一个条件(包含  “TJ”  )的语句:

grep '1805' CloudPayment.log  > out.log

cat  CloudPayment.log | grep '1805' > out.log

2、满足两个条件中的一个条件(包含“1805” 或者 包含“1905”)的命令:

egrep '18051905' CloudPayment.log > out.log

grep -E '1805|1905' CloudPayment.log > out.log

cat  CloudPayment.log | grep -E '1805|1905'  > out.log

3、同时满足两个条件中(包含“1805” 和 “1905”)的命令:

grep '1805'  CloudPayment.log  | grep '1905'  > out.log

egrep '1805.*1905| 1905.*1805' CloudPayment.log > out.log 

cat CloudPayment.log | grep "1805"  | grep "1905"  > out.log

PS: 符号“>”表示擦除后写入文档  ; “>>”表示追加到文档

部分字符需要使用斜杠转译,如减号等
 

4、grep和tee结合:

  • 在文件 CloudPayment.log中搜索订单号1905,
  • 并将搜索结果输出到out.log

grep '18051114551940610000' CloudPayment.log | tee -a out.log

 

关于grep,请参考:

Linux文本搜索:grep命令

更多推荐

Linux:查找指定字符串,并将结果输出到指定文件