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

learn more… | top users | synonyms

1
vote
1answer
134 views

Matches in color, others just shown

I'm just trying to get grep to show all the lines, but the ones that match should have the matching text colored. Specifically I need this for something like this: tail -f file.log | grep --color ...
2
votes
4answers
2k views

Outputting grep to multiple variables

I what to have bash script to grep output to multiple variables but have no idea how to do that: command |grep bla > $result1 $result2 etc... Any ideas? S
1
vote
4answers
2k views

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 ...
12
votes
2answers
11k views

When to use single-quote, double-quote in grep?

While trying to search for a simple pattern "hello" in a file, all the following forms of grep work: grep hello file1 grep 'hello' file1 grep "hello" file1 Is there a specific case where one of ...
0
votes
3answers
2k views

Get results from grep in the order they appear?

I'm trying to grep a log file to only show lines that match a certain session ID. Thus far, it works great. However, when I get the results of my grep command, I'm not getting the entries in the ...
1
vote
3answers
1k views

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, ...
2
votes
2answers
4k views

ps ax | grep java with no wrapping in the terminal?

Is there a way to execute ps ax | grep java without it wrapping on the terminal?
6
votes
2answers
3k views

How do I show filenames only after a keyword grep search?

I currently have n data files in a directory where each file has at most 1 line of very long data. My directory structure is director/ data1.json data2.json data3.json I know that at ...
3
votes
2answers
733 views

Local full text index for a directory tree, a quicker alternative for grep -R

I have a large directory tree of source files. I want to search around all these files. My first instinct is to use grep -R or ack, but either way they just sequentially read all the files. Is there ...
3
votes
2answers
2k views

How can I use grep to find the most frequently recurring errors in my log file?

I've got a PHP application that is generating large amounts of warnings and notices in the log file.. I'm fixing these one at a time. I would like to be able to fix the most frequently occurring ...
14
votes
4answers
16k views

Linux Command to find Strings in Binary or non ascii file

Is there any linux command to extracts all the ascii strings from an executable or other binary file? I suppose I could do it with a grep, but I remember hearing somewhere that such a command existed? ...
1
vote
5answers
4k views

Don't need the whole line, just the match from regular expression

I simply need to get the match from a regular expression: $ cat myfile.txt | SOMETHING_HERE "/(\w).+/" The output has to be only what was matched, inside the parenthesis. Don't think I can use ...
1
vote
3answers
3k views

SED Find & Replace w\ Regular Expressions

Alright, So i'm confused & out of ideas. I'm trying to replace all the old IP addresses with a new one. find -type f | grep \.php$ | xargs sed -r -i ...
2
votes
9answers
1k views

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 ...
8
votes
6answers
6k views

How do i get the default gateway in LINUX given the destination?

I'm trying to get the default gateway, using the destination 0.0.0.0 i used this command: netstat -rn | grep 0.0.0.0 and it returns this list: Destination - Gateway - Genmask - Flags - ...
1
vote
4answers
470 views

Unable to grep sourced Files in Vim

I have files which I source in my files. I want to search them, when I am at a file which have these sources. I run unsuccessfully !bufdo grep source and !bufdo grep source % Example of ...
1
vote
1answer
105 views

ignoring errors in find / output

how do I filter out permissions errors out of find / | grep foo output?
47
votes
12answers
63k views

Do you have any useful awk and grep scripts for parsing apache logs? [closed]

I can use log analyzers, but often I need to parse recent web logs to see what's happening at the moment. I sometimes do things like to figure out top 10 ips that request a certain file cat foo.log ...
1
vote
1answer
609 views

How does one simular the old unix grep -S strict functionality in linux (CentOS 5.2)

I am grepping the output of a command and I wish to only return specific, strict results. I remember some iteration of grep had a strict option -s/--strict. example: command | grep -i bytes This ...
26
votes
5answers
27k views

Recursive text search with grep and file patterns

Given this example folder structure: /folder1/file1.txt /folder1/file2.djd /folder2/file3.txt /folder2/file2.fha How do I do a recursive text search on all *.txt files with grep from "/"? ("grep ...
6
votes
6answers
10k views

How to Find a file in FreeBSD

I'm trying to locate all copies of example.filename on my FreeBSD server. What's the best / easiest / most efficient way to do this?