RHEL/Centos7 Shell tips1 -- grep

66 篇文章 0 订阅

OR

 

grep 'pattern1\|pattern2' filename

grep -E 'pattern1|pattern2' filename

 

 

Grep AND 

grep中并没有AND操作符,但你可以使用-E选项来模拟。

grep -E 'pattern1.*pattern2' filename
grep -E 'pattern1.*pattern2|pattern2.*pattern1' filename 

 

#filename only for multiple search

#  grep -l  show file name only 

## grep 2 different keyword in different lines! 

grep  -l   KeyWork1_Clear  source_folder/    -R     |xargs grep  -l     KeyWorkd2_Even

 

# after-context or backward context

   -A NUM, --after-context=NUM
              Print NUM lines of trailing context after matching  lines.   Places  a  line  containing  a  group
              separator  (described  under --group-separator) between contiguous groups of matches.  With the -o
              or --only-matching option, this has no effect and a warning is given.

       -B NUM, --before-context=NUM
              Print NUM lines of leading context before matching  lines.   Places  a  line  containing  a  group
              separator  (described  under --group-separator) between contiguous groups of matches.  With the -o
              or --only-matching option, this has no effect and a warning is given.

 

Example 

[lake@localhost]$ grep  "P/f -> schedule"  log-0609.txt
407175 11:19:48.698 EventLogcache(343) Debug: EventLogCollector[1]::LogEvent: P/f -> schedule: (2, 2068, 21250) 25646: 2021-06-09 10:30:00 [01:00:00] plus plus, running: no, free
[lake@localhost]$ grep  -A  5    "P/f -> schedule"  log-0609.txt
407175 11:19:48.698 Debug: EventLogCollector[1]::LogEvent: P/f -> schedule: (2, 2068, 21250) 25646: 2021-06-09 10:30:00 [01:00:00] plus plus, running: no, free
407176 11:19:48.699 Debug: EventLogDatabase::MakeSchedule: UPDATE Events AS e SET type = 3, runningStatus = 1 WHERE ((e.onid IS 2) AND ((e.tsid IS 2068) AND (e.sid IS 21250))) AND ((e.eid IS 25646) AND (e.type IS NOT 3))
407177 11:19:48.700 Debug: EventLogSession[1]::OnSectionData: Processed 19 sections (pid 3004) and  1 events in 5 ms (   6 events/s; limit 1536 h)
407178 11:19:48.701 Debug: EventLogSession[2]::OnSectionData: Processed  1 sections (pid 3842) and  0 events in 0 ms (   0 events/s; limit 1536 h)
407179 11:19:48.705 Debug: EventLogSession[1]::ProcessReceiveMessages: Ignore EventLog for (2, 2053, 10147): unknown service
407180 11:19:48.705 Debug: EventLogSession[1]::ProcessReceiveMessages: Ignore EventLog for (2, 2063, 20730): unknown service




[lake@localhost]$ grep  -B  5  -A 5    "P/f -> schedule"  log-0609.txt
407170 11:19:48.697 Debug: EventLogCollector[1]::LogEvents: Adding/updating events (pid 3004, EventLog 0xd1, section 1, v12) [1 events]
407171 11:19:48.697 Debug: EventLogCollector[1]::LogEvent:   (2, 2068, 21250) 60318: 2021-06-09 03:55:00 [02:05:00] following, running: no, free
407172 11:19:48.697 Debug: EventLogDatabase::AddOrUpdateEventLogEvents: Inserted 1/1 events
407173 11:19:48.698 Debug: EventLogDatabase::SetEventLogQuery: query: SELECT e.onid, e.tsid, e.sid, e.eid, e.type, e.startTime, e.duration, e.runningStatus, e.freeCaMode FROM Events AS e WHERE ((e.onid IS 2) AND ((e.tsid IS 2068) AND (e.sid IS 21250))) AND ((NOT (e.eid IN (25643,25644,25645,25718,60318,60319))) AND (e.type IS NOT 3))
407174 11:19:48.698 Debug: EventLogDatabase::GetEventLogEvents: 1 event(s) (limit 0, offset 0) in 1.16 ms
407175 11:19:48.698 Debug: EventLogCollector[1]::LogEvent: P/f -> schedule: (2, 2068, 21250) 25646: 2021-06-09 10:30:00 [01:00:00] plus plus, running: no, free
407176 11:19:48.699 Debug: EventLogDatabase::MakeSchedule: UPDATE Events AS e SET type = 3, runningStatus = 1 WHERE ((e.onid IS 2) AND ((e.tsid IS 2068) AND (e.sid IS 21250))) AND ((e.eid IS 25646) AND (e.type IS NOT 3))
407177 11:19:48.700 Debug: EventLogSession[1]::OnSectionData: Processed 19 sections (pid 3004) and  1 events in 5 ms (   6 events/s; limit 1536 h)
407178 11:19:48.701 Debug: EventLogSession[2]::OnSectionData: Processed  1 sections (pid 3842) and  0 events in 0 ms (   0 events/s; limit 1536 h)
407179 11:19:48.705 Debug: EventLogSession[1]::ProcessReceiveMessages: Ignore EventLog for (2, 2053, 10147): unknown service
407180 11:19:48.705 Debug: EventLogSession[1]::ProcessReceiveMessages: Ignore EventLog for (2, 2063, 20730): unknown service
 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值