grep a Unix command-line utility which searches input passed to it for lines matching a regular expression, and prints the results.

learn more… | top users | synonyms

7
votes
2answers
8k views

How can I “grep” recursively filtering the name of the files I want with wildcards?

When I want to perform a recursive grep search in the current directory, I usually do: grep -ir "string" . But that command searches inside all kinds of files, including binary files (pictures, ...
0
votes
1answer
22 views

How do I correctly return context from a gnuwin32 grep (grep in windows cmd)?

I want to return a line of context after the string I'm searching for as per grep --help Context control: -B, --before-context=NUM print NUM lines of leading context -A, --after-context=NUM ...
11
votes
14answers
19k views

Monitoring a file until a string is found

I am using tail -f to monitor a log file that is being actively written to. When a certain string is written to the log file, I want to quit the monitoring, and continue with the rest of my script. ...
0
votes
1answer
21 views

How to grep through HTML using GNU grep 2.12 and bash 4.2.37?

I've never used grep to parse HTML files, and am having the following problem: grep -Po "(?s)(<h2>.+?<!-- /endcontent -->)" input.html > output.html -bash: !--: event not found I ...
0
votes
1answer
24 views

grep: display all output but highlight search matches

in bash, if I want to execute a command and only display output lines that matches a certain pattern, I can pipe it to grep, like file testfile hello there my friends command $ cat testfile | ...
1
vote
0answers
17 views

grep php output show more than grep query

I'm having an issue where php file | grep "query"'s output shows EVERYTHING, not just the grep'd output. EX: php /vagrant/code/test.php | grep "Do not show anything" Shows anything echo'd in the ...
-1
votes
1answer
245 views

How to grep rows that have value less than 0.2 in a specific column? [closed]

ID RT EZ Z0 Z1 Z2 RHO PHE 1889 UN NA 1.0000 0.0000 0.0000 0.8765 -1 1890 UN NA 1.0000 0.0000 0.0000 0.4567 -1 1891 UN NA 1.0000 0.0000 ...
9
votes
7answers
3k views

Unicode grep for Windows [closed]

Is there a Unicode-aware grep for Windows 32-bit?
0
votes
1answer
39 views

BASH : grep count same word occurrence

Is it possible to count the maximum number of occurrences of a word in a string using only grep ? Here is an example of what I want : script.sh "aaaa bbbb ccc bbbb azesd bbbb" would return bbbb ...
0
votes
2answers
27 views

grep and sed with pipe from tail -f appears to be caching

I am trying to get a working system to monitor special logs. I usually just want a very specific pattern which I extract using grep and a pipe from tail -f. I have noticed that grep does not output ...
0
votes
2answers
16 views

Grep invert match with context

I am trying to grep a file with invert match, but also not match every line occurring right after the matching lines. So I have the following contents in a file called testing_grep: ...
1
vote
1answer
22 views

Grep with string comparison: return only lines “higher than” a timestamp

I have an email log file which records when an email went out, and who to. This gets logrotated and so there are a mixture of zipped and unzipped log files going back a week or so. I'm currently ...
0
votes
1answer
370 views

Remove grep's line number output in Redhat 5.9

I havent used RH 5.9 until now. I started with 6 but we have some 5.9 servers. The syntax with 5.9 is a bit different with some things. grep for example will output a number line before the actual ...
2
votes
1answer
25 views

grep -l output filenames with spaces

I want to loop over files with for f in `grep -rsl "foo" . `: do sed -i -- "s/foo/bar/g" $f; done; But since filenames contain spaces, a filename is split whenever a space is found. How can I ...
14
votes
8answers
43k views

What regular expression can I use to match an IP address?

With the following grep syntax I want to match all IP address in a file (from a ksh script) grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' file The problem: It also matches words ...
4
votes
6answers
5k views

grep count multiple occurrences

Is it possible to do a grep count of multiple occurrences in a file in one single command? For example: $ cat > file blah alfa beta blah blah blahgamma gamma I can do: grep -c 'alfa' file 1 ...
1
vote
1answer
26 views

How to serach for a line which contains specific string in Bash?

I've got a file which contains some amount of lines, I want to look for a specific string, and if the file contains it, then I want to print a different line from the same file. for example, let's ...
6
votes
3answers
9k views

Mac OS X search and replace tool with regular expression support

I'm looking for a regular expression based search/replace GUI tool that is able to handle multiple files/subdirectories, something like grepWin but for Mac OS X. PS. I'm aware of grep and I don't ...
1
vote
1answer
15 views

Grep Whitespace across multiple lines

Given the following in a bunch of text files (.vb): Partial Class [A-Za-z0-9_] Inherits System.Web.UI.Page End Class I'm trying to grep for files that have this basically empty code file, to ...
19
votes
5answers
14k views

Excluding grep from process list

I have cobbled together a command to return the process ID of a running daemon: ps aux | grep daemon_name | awk "{ print \$2 }" It works perfectly and returns the PID, but it also returns a second ...
0
votes
1answer
39 views

How to grep for line numbers in a binary file?

I'm on Centos 5 Linux and using GNU grep v2.5.1 and looking at a 36GB log file. It is huge and I need to find around a million lines starting from the occurrence of a string 6307459 in the log file ...
0
votes
1answer
33 views

Why is the Windows Explorer not able to find a UUID string in a list of text files?

I have a directory with all my PUtty log files. Now I would like to find the files containing a UUID. I know that the UUID is in one or more files. I tried it with Windows Explorer. I searched with ...
0
votes
1answer
30 views

Why is grep missing missing matches when searching multiple directories?

Trying to grep the files in several child directories, grep returns nothing. ~/box/raw $ grep ":2259\"" f*/hh*.adt ~/box/raw $ But when I descend into one of the child directories, grep finds a ...
1
vote
0answers
26 views

ack.pl tool and ack.pl flags + how to ignore files with S attr

I am using the ack.pl tool in order to search string or IP’s in files The official site of ack.pl is - http://beyondgrep.com/documentation/ Example of ack.pl CLI ( want to find the string ...
0
votes
1answer
18 views

Using grep for text search

I need to search the filesystem for text strings that match some string. I'm trying to get where the commands are used, meaning in which files they are called or used. I need to find every file where ...
0
votes
1answer
18 views

Find a <a> tag that starts with a space in grep

I want to search an entire codebase for spaces after an < a> tags. They are visible as underlined spaces. Is this possible with regular expressions and grep? My first guess is that I must use a ...
1
vote
2answers
37 views

Exclude lines that have duplicate words between delimiters

I have a folder structure that has been (badly) maintained by a number of automated jobs. One of the side effects of these jobs appear to be that it creates duplicate folder names (and subsequently ...
80
votes
11answers
164k views

Command prompt (Windows 7) grep equivalent?

Is there a command prompt (Windows 7) grep equivalent? That is, I want to filter out the results of a command: Bash use: ls | grep root What would it be from a Windows command prompt?
0
votes
1answer
30 views

Removing lines in text document that end the same

We have a script that downloads a list of domains for our squid box to block, but we keep getting warnings like the following: 2015/03/02 17:08:47| WARNING: You should probably remove '.artnau.com' ...
0
votes
2answers
36 views

How to save matching words from output of dmesg in a list

I am connecting USB-Serial devices to my device using different ports and serial-USB devices sometimes show up as 'ttyUSB0', sometimes 'ttyUSB1' or 'ttyUSB2'. How can I write a script to extract all ...
1
vote
1answer
48 views

Piping lines to repeat commands

If my grep operation returns a list of IDs like in the following, can I somehow feed/pipe each line to a commandline command's parameter?: 12345 84758 49549 .. Like for example with the above ...
1
vote
2answers
30 views

Easy way to grep for text in one file only in directories containing a second file

Background: We have a process that is not running correctly. It is supposed to only run on files with patterns like "AAA*.x12". However, it is also running on files similar to "BBB*.x12" Each ...
0
votes
0answers
78 views

how to grep exact pattern

I’ve tried several grep / egrep ideas with different options but none worked here. I’m trying to grep exact match of the pattern I’m looking in a log. For example I want only a pattern “ERROR” to get ...
3
votes
2answers
5k views

Recursive zgrep not working

I have a directory hierarchy that contains numerous .gz files. I want to be able to recursively grep them for the string "foo". From what I've read online the following should work: zgrep -R -H ...
0
votes
1answer
130 views

How to find the total number of processes in Unix/Linux shell script

I’m trying to find the total lines of running processes excepting the commands I’m using to create the listing. Then to parse out the userID and the PID into a new list. All within the same shell. ...
0
votes
1answer
48 views

Piping grep causes error $'\302\240grep': command not found on linux

Sometimes when I'm catting & grepping a file, I see this error come up: $ cat something.txt | grep "some text" -bash: $'\302\240grep': command not found When I re-type the command, it works as ...
17
votes
5answers
9k views

Grep tool for XML [closed]

I am looking for a good tool to perform grep-like operations on XML - for example, extract certain attributes only. Grep itself can't handle it - any DFA-equivalent tool can handle only non recursive ...
0
votes
1answer
25 views

grep % through a file

I am running an import job on a really large mysql file that for the most part doesn't have line breaks. Using mysql process list I was able to fine the ID of the currently inserting record. What I ...
9
votes
4answers
16k views

Grep multiline pattern

How do I search for a phrase over multiple lines? E.g. Lets have the phrase "my ice tea" then it may be wrapped in text files: as js skdfh dfh djh sf my ice tea. grep will not match since there is ...
1
vote
2answers
556 views

Strange grepped process list

When I run ps fax|grep grep it shows one process like: 2618 pts/0 R+ 0:00 \_ grep --color=auto grep That would be OK, but when I run ps fax|grep -v dummy_text grep process ...
1
vote
2answers
961 views

How to find the last match of a string in a bunch of files

I have a bunch of files, I'd like to find the last match of a string in each of them. grep text *.file gives me all the matches not the last ones. ls *.file | xargs grep text | tail -n 1 gives me ...
3
votes
3answers
4k views

regex : does not begin by “pattern”

I have a lot of lines in my LIST file and want to list only lines whose name does not start by (or contains) "git". So far I have : cat LIST | grep ^[^g] but I would like something like : #not ...
1
vote
1answer
134 views

grep: output specific line after match

Is there a way, using grep, to output the line that falls a specific number of lines after the match is found? For example, I want to output the line with a match, the 8th line after the match, and ...
1
vote
2answers
52 views

Linux: How to kill a root owned process by parameter's name?

I would like to know how to kill processes owned by the root based on their parameter's information: root 3176 0.0 0.8 3604 2252 ? S 21:33 0:00 sudo python main.py root ...
0
votes
1answer
40 views

Why grep shows me output that does not contain the search word?

I want to check if the sensu service is installed. I ran this command service --status-all| grep sensu and here is the output vagrant@vagrant-ubuntu-trusty-64:~$ service --status-all| grep sensu [ ? ...
0
votes
2answers
179 views

Case sensitive searching in Linux

In Linux, I want to search for a word in all files in a directory (also in subfolders), and the search must be case sensitive. The search must give me all file names, directory names, and line numbers ...
2
votes
1answer
3k views

Using Mac OS X terminal to copy a selection of folders to a new location, with merge behavior

I have a folder 'foo' that contains a lot of sub folders, e.g. foo |---20101 |---20102 |---20103 |---20111 |---20112 |---20113 There are way more than this, but hopefully it explains the ...
4
votes
1answer
64 views

Can I create a “file” that, when opened, actually gives the output of a command?

I've found myself in a couple of situations now where I'd like to have such a "file" that essentially runs a script whenever it's "opened", allowing me to "read" it's output. For example, I might ...
0
votes
3answers
22 views

Filtering 2nd field from a data set and then using uniq on the output

I've got a dataset that goes like this: AAAAA 11111 Data1 AAAAA 11111 Data2 AAAAA 11111 Data3 AAAAA 11112 Data4 AAAAA 11112 Data5 AAAAA 11112 Data6 AAAAA 11112 Data7 AAAAA 11113 Data8 AAAAA 11114 ...
-1
votes
2answers
1k views

Getting this simple regular expression to match in grep

I want to match a quote, 2, a space, and any character that is not a literal dot. This is using GnuWin32 grep. Not Cygwin's grep. C:\>echo "2 008abc.html" | grep -oiP \"2 [^.] grep: [^.]': No ...