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
1
vote
0 answers

Grep error or limitation reached on 1.2GB text file?

grep on large file followed by tail produces incorrect result, see proof below. The file is 1.2GB large, but grep should process it as a stream, so where could be a problem? root@condor1796 /home/glassfish/apache-tomcat-8.5.5/logs # tail -n 20000…
Mladen Adamovic
  • 599
  • 1
  • 3
  • 14
1
vote
1 answer

Can I filter output from `tail` with the `-f` flag?

I'd like to tail -f the output of access_log on RHEL 6.8 but pipe and grep that output to act as a filter. Is there such an option? That is I'd like live output from: # tail -f error_log | grep <> Currently I'm doing something…
Rick
  • 299
  • 1
  • 4
  • 12
1
vote
1 answer

How to write a shell script to search from a position in file instead to start from beginning of the file again

I am trying to write a shell script to find value stored after a repetitive word in a big file with millions of lines using for loop. After the finding the repetitive word how i make script to start searching after the present line in file so that…
1
vote
1 answer

grep command to extract data from a file

I have a file that has this line in it: $n22(s:Tstring) = "252"; I'm trying to write a shell command to grep the file and only return 252. This is what I have so far: grep -o '$n22(s:Tstring).*;' /etc/test/testfile.cfg $n22(s:Tstring) = …
Happydevdays
  • 135
  • 1
  • 3
1
vote
4 answers

ls | grep regex, ignore files with .tab,

I know some regex but I don't know how to get this to work. I want to list all files that don't have .tab. and don't have ~ at the end of the filename and aren't a .o (or .bin) I can list all the files that have .tab. by writing ls | grep…
user274
1
vote
1 answer

Search lighttpd access log

The access-log on my lighttpd server is kind of huge, apx 5GB. Now I need to extract all data from a given date, 12th of February, from the log file and if possible save to new file. Is it possible to search the file somehow? I have tried below sed…
Andy
  • 13
  • 2
1
vote
3 answers

How to grep (or other command?) for first instance to last instance in a log?

How does one grep/search a text file so that the results show the first line with the string, and then every other line until the last line with the string? So, if I have a file that looks like this: A A B C C B A A And I perform this command…
IVR Avenger
  • 325
  • 1
  • 5
  • 16
1
vote
5 answers

Get the pid if 2 tomcat(s) is running

I have 2 tomcat's running, how do I get the pid if both have similar names? ps -ef | grep java root 12952 1 0 10:01 pts/0 00:00:03 /usr/lib/jvm/jre/bin/java…
user3789893
  • 11
  • 1
  • 4
1
vote
3 answers

Shell Script: How do I turn "virsh list | grep MediaWiki" into an if condition?

I'm trying to determine if a given Virtual Machine is running using a shell script. The command "virsh list | grep MediaWiki", when run manually, returns one line if the Virtual Machine is running, and returns nothing when it's not. I'm trying to…
Nick
  • 4,503
  • 29
  • 69
  • 97
1
vote
1 answer

Finding strings in files with relative path

I don't understand why this two commands don't provide the same result (the differrence is only relative vs. absolute path), can somebody explain it? annika /srv/www/pages/com.example.www/www/povruc # find /srv/www/pages/com.example.www/www | xargs…
1
vote
1 answer

Regex matching first word and any word

I have a log file with a list of many entries. With grep regex I want to match the first word and another word which can be anywhere in the string. For example, if I specified "user1" the search would search: grep -E '^(IP_CONNECT|IP_DISCONNECT)…
dukevin
  • 1,630
  • 3
  • 18
  • 25
1
vote
1 answer

Refine grep look behind to avoid numbers

When I query docker images, I get this: #> docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE local/debian 7.5 172c7702a46f 2 weeks ago 175.1 MB local/debian …
balin
  • 123
  • 1
  • 5
1
vote
2 answers

How to report filenames found by strings after being piped through grep?

I've been around *nix long enough to remember having done this in the past, and now those neural pathways are gone... I'm searching /usr/local/lib for files that contain img_convert because I'm getting a link error and want to find the library to…
Alan
  • 541
  • 1
  • 6
  • 20
1
vote
3 answers

Capture piped multiline grep output into a variable

I'm using Zabbix's zabbix_sender.sh script to push exception stack traces to my remote Zabbix monitoring server. zabbix_sender.sh requires a key and a value for any data that it sends. It can read data from stdin, but this overrides any key variable…
skyler
  • 465
  • 3
  • 8
  • 17
1
vote
1 answer

Get some meaning from apache logs with awk and grep

I am trying to have some meaning from my apache log files: I want to parse my access log and have some statistics about 200 status code hits (how many times each of them was hit). So I tried to learn some awk magic and here what I got right…
Salvador Dali
  • 965
  • 6
  • 20
  • 31