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
2 answers

How to grep IP address and number of access

I am using the following command to get the number of hits of an IP address: grep "21/Jul/2013:22" /var/log/ispconfig/httpd/*/access.log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c | awk '{ if ($1 > 10) print…
jaYPabs
  • 299
  • 1
  • 4
  • 20
2
votes
9 answers

How to reproduce grep's --recursive option in an old version of grep

I am working on an ancient UNIX whose grep lacks the -r/--recursive option. I need to find an error that our application is causing, but I do not know which log file our application is writing errors to. However, I do know that the log file is…
Josh
2
votes
1 answer

finding files that match a precise size: a multiple of 4096 bytes

I have several drupal sites running on my local machine with WAMP installed (apache 2.2.17, php 5.3.4, and mysql 5.1.53). Whenever I try to visit the administrative page, the php process seems to die. From apache_error.log: [Fri Nov 09 10:43:26…
doub1ejack
  • 567
  • 1
  • 6
  • 12
2
votes
3 answers

grep pattern interpretted differently in 2 different systems with same grep version

We manufacture a linux appliance for data centers, and all are running fedora installed from the same kickstart process. There are different hardware versions, some with IDE hard drives and some SCSI, so the filesystems may be at /dev/sdaN or…
2
votes
2 answers

Gathering IP's from a complicated log

I have a question regarding the use of some more advanced grep, awk, sed. I have a log file, for a proprietary MTA, that contains IP's in a string, delimited by [redacted]^~x.x.x.x^[redacted]. So far all of my grepping, awking, and sedding hasn't…
Harry
  • 128
  • 5
2
votes
2 answers

Grep to find lines starting at pattern A until pattern B is matched

I have a log that contains bits like this: [2012-04-16 15:16:43,827: DEBUG/PoolWorker-2] {'feed': {}, 'bozo': 1, 'bozo_exception': URLError(error(110, 'Connection timed out'),), 'entries': []} [2012-04-16 15:16:43,827: ERROR/PoolWorker-2]…
Steve Bennett
  • 5,750
  • 12
  • 47
  • 59
2
votes
4 answers

How do I make grep results colored?

I have some output of my program: # php check.php | grep -E "rule_1|rule_4" I would like results equaling to rule_1 to be red and results equaling to rule_4 to be blue. Is this possible, because at this moment, everything is colored red.
user1081056
  • 123
  • 4
2
votes
5 answers

solaris + grep syntax in solaris

my target is to match Exactly the string snmpmanager from hosts file on solaris & linux the following command work on Linux (red-hat 5.1) but not for SunOS , please advice how to fit the syntax to solaris? example from solaris OS grep -icE…
Eytan
  • 611
  • 6
  • 13
  • 27
2
votes
2 answers

egrep not working in crontab

I have a simple bash script wich works fine when running in command line, but not in crontab: #!/bin/bash PATH=/usr/bin:/bin for f in /data/home/cwolff/tmp/*access_log*.txt; do egrep "r:[A-Z]+ \S+[^\.\s]{5} " $f >> $f.min done When running in…
rontron
  • 23
  • 2
2
votes
4 answers

grep and tabs: no match

#cat sample 1 -1 2 2 2 2 2 1-1 3 I need to get all the lines that contains negative value, that is 1st line only. Values are tab-separated. First I tried # grep "\-1" sample 1 -1 2 2 1-1 3 But if I try grep "\t\-1" sample I get…
Putnik
  • 2,217
  • 4
  • 27
  • 43
2
votes
1 answer

How to find a file that contains the specified string in FreeBSD?

I'm searching for the way to find a file that contains specified string text. It should be fast as possible but its not that important. I was reading the manual, and I've build something like that: grep my_string * -r and it works at all, but if…
Cyclone
  • 260
  • 1
  • 6
  • 20
2
votes
4 answers

GREP show lines that contain this but not that

I would like to search for lines that contain "uploaded" but do not contain "09" Is there a way to do this with grep? (CentOS 5.6 if it matters).
JT White
  • 185
  • 1
  • 1
  • 6
2
votes
1 answer

compare first or third position

The mysql general log file looks like this... 110822 14:41:14 103700 Query SHOW FULL TABLES FROM `engine` LIKE 'PROBABLYNOT' 103700 Query SHOW FULL TABLES FROM `engine` LIKE 'PROBABLYNOT' 110822 15:01:14 103701 Query SHOW…
shantanuo
  • 3,579
  • 8
  • 49
  • 66
2
votes
2 answers

Locate a string in a folder and the file it came from?

I am trying to find some keywords in my /var/log directory, so using cd /var/log cat * | grep keyword I find the string is in that directory and see the lines it exists on, but don't know which file it came from. How can I locate the string, and…
wjimenez5271
  • 729
  • 2
  • 6
  • 16
2
votes
2 answers

find files and search for within tail

The following is working as expected. find /opt/ -name "somefile.out" -exec grep 'Connection refused' {} \; | more But if I want to search only in the tail of the found files, I can not add tail or tail -100 like this... find /opt/ -name…
shantanuo
  • 3,579
  • 8
  • 49
  • 66