Questions tagged [grep]

grep is a command-line tool for searching text patterns in files.

The grep utility searches a pattern (regular expression) in a text file. There are many options to control how matches are performed and how to display matches.

External references

Tutorials

Further reading

See also grep on Unix & Linux Stack Exchange for more detailed reading.

326 questions
2
votes
5 answers

remove 2 lines from output, grep match regular expression plus next 1

i have a log file from postgresql that has log entries of the format; LOG: execute : /match this here/ DETAIL: parameters: /also want to filter this line/ I thought it might be possible with grep -v --after-context=1 'match this here'…
Tom
  • 11,176
  • 5
  • 41
  • 63
2
votes
1 answer

Logcheck: wildcards which include non-latin characters

On my mail server, I have a custom logcheck rule as follows, which is intended to filter messages from deliver: ^\w{3} [ :0-9]{11} [._[:alnum:]-]+ deliver\.*\): msgid=.*: saved mail to.*$ Unfortunately, the msgid=.* wildcard does not match if there…
Matt Holgate
  • 131
  • 1
2
votes
2 answers

ignore lines grep

I have a very annoying message being output from a process I'm running. I'd rather not remove the line, but simply remove it with grep The messages to ignore all contain the word "requests". I could easily ONLY these lines with $> myproc | grep…
corsiKa
  • 383
  • 1
  • 8
  • 19
2
votes
3 answers

alias to replace a text in file

here is a practical situation.I facing some of my files where there is a common string in these files.I usually will open vi and do some thing like :%s/text/replacement/g and I have to do it in many files many many times. Is there some easy way…
Registered User
  • 1,463
  • 5
  • 18
  • 37
2
votes
4 answers

Is there a simple command-line HTTP proxy that outputs to STDOUT?

Is there a command-line HTTP proxy that outputs to STDOUT so I can use it with Unix pipes? I want to do something like this: Start the proxy at the command-line: $ proxy -p 8888 | grep "Text I'm interested in" > ~/my_log.txt Configure my browser…
richardkmiller
  • 255
  • 2
  • 12
2
votes
5 answers

Find files containing a string on the whole filesystem

I need to find all the instances of a given string in the whole filesystem, because I don't remember in which configuration files, script or any other programs I put it and I need to update that string with a new one. I tried with the following…
Fabio
  • 1,299
  • 2
  • 13
  • 18
2
votes
3 answers

tail -f and then exit on matching string

I am trying to configure a startup script which will startup tomcat, monitor the catalina.out for the string "Server startup", and then run another process. I have been trying various combinations of tail -f with grep and awk, but haven't got…
Patrick
  • 192
  • 1
  • 3
  • 10
2
votes
4 answers

grep'ing through mailq

I want to filter some of the mail IDs returned by mailq (Postfix). However, the format is not very "grep-friendly", since the information for a single mail spans multiple lines: 9F701869D2 1356 Mon Aug 23 12:13:43 some@sender (host…
Heinzi
  • 2,217
  • 5
  • 32
  • 52
2
votes
1 answer

Find occurrences of a file of words in a dictionary

I have a number of search logs that I want to compare against certain dictionary files. Once I process the search logs to filter out certain entries and get all the search terms into separate lines, what is an easy way to figure out how many of the…
Chris Henry
  • 1,552
  • 3
  • 15
  • 15
2
votes
2 answers

How can I remove malware code in multiple files with sed?

I've this malware code in so many .html and .php files on the server. I need to remove them using sed -i expression search all files under directory /home/ find infected files remove the code by replacing it with a white space var usikwseoomg…
user47556
  • 509
  • 1
  • 5
  • 11
2
votes
2 answers

Send email based on grep results

I'm using WebInject (CLI not GUI) to test out online web services. I was going to go with a third party until I found this little gem and realized what I could save... What I want to accomplish is to grep the results of WebInject (Perl script) . If…
JohnyD
  • 1,614
  • 3
  • 20
  • 29
2
votes
2 answers

Advanced grep, where string doesn't begin with a URL

I'm seeing tons of error logs on our site that are looking for favicon.ico. The favicon is now hosted off of amazon S3 but it appears somewhere we still have a link to the old one that I can't find anywhere (I'm a new employee here so I'm not too…
Ben
  • 3,800
  • 18
  • 65
  • 96
2
votes
2 answers

greping files question

I've been using grep to run a few PII scans and while it's finding results, it's indeed finding too many false positives. Is there a way that I can tell grep not to trigger a match for a file unless it contains other data? For instance, can I tell…
tearman
  • 425
  • 1
  • 7
  • 20
2
votes
2 answers

Spamassassin one-liner to tag & move mail with an X-Spam-Flag: YES to a new directory?

Say you have a directory with tens of thousands of messages in it. And you want to separate the spam from the non-spam. Specifically, you would like to: Run spamassassin against the directory, tagging each message with an X-Spam-Flag: YES if it…
ane
  • 171
  • 1
  • 4
  • 16
2
votes
2 answers

Best way to filter output by date range

I need to filter a row of a csv file by a date. The file is structured as so: test121smith@example.com active 01/24/11 10:04 07/23/23 16:56 test121johnson@example.com …
dj423
  • 23
  • 3