get two/more specific words on a line and print next few lines
currently I am searching one word at last occurrence in file for which I use following thing.
Code: grep -A 20 -e 'address 5' input | tail -n 21 > output This works great for last occurrence searching for one word and then print that line and next 20 lines. but If i want to search 2 or 3 words? like last occurrence of "address 5" and "usb", together in one line... for example as in following line: Code:
Apr 20 15:58:47 box2 kernel: usb 1-3: USB disconnect, address 5 Please note: I want to get last occurrence of word "address 5" AND "usb" in file and next 20 lines. thanks in advance |
Use a regular expression in the pattern for grep. For instance:
Code:
grep -e 'USB.*address 5' /var/log/messages |
Quote:
Daniel B. Martin |
Hi.
I have used glark for this kind of work: Code:
NAME The code is a Ruby script, and it is fairly slow, of the 20+ utilities and languages that I compared for string searches, it was near the lower end for speed: e.g. 10 times slower than sed. The flexibility, however, is amazing. Best wishes ... cheers, makyo |
Quote:
Code:
egrep -A 4 "chamber" $InFile \ |
Quote:
Code:
grep -e 'USB\|address\|mount' /var/log/messages If, for instance, one wants to find lines that contain 'address' following 'USB' or 'mount' following 'EXT4', it could be written: Code:
grep -e 'USB.*address\|EXT4.*mounted' /var/log/messages |
Quote:
Quote:
|
Hi.
Here is an example of glark on chapter one of Moby Dick: Code:
#!/usr/bin/env bash Code:
% ./s1 |
Quote:
Quote:
Code:
grep -e 'USB.*address 5' /var/log/messages Code:
grep -e 'USB.*address\|EXT4.*mounted' /var/log/messages But perhaps I'm completely misunderstanding the point of the OP. Would the OP be so kind as to further comment on the answers? |
ok. sorry for any confusion that I'm making. Here is exact scenario:
I have following line in log file: Quote:
and I have only two words with me Quote:
@danielbmartin: egrep didn't work. tried this: Quote:
Quote:
I hope I made it clear. if still not then do let me know. thanks for the efforts of all guys. |
Try this:
Code:
egrep -A 16 'usb 1-3.*address 3' logfile |
I just added a post to your other related thread.
http://www.linuxquestions.org/questi...ic-word-940850 Questions concerning a single topic should really be kept to one thread, to keep down the amount of duplicated effort. |
All times are GMT -5. The time now is 11:03 AM. |