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

learn more… | top users | synonyms

3
votes
5answers
286 views

evaluate multiple patterns from program output and write into pattern specific files

I have a script outputting some value/numbers and I want to split those into two files. I am looking at something like: ./runme.sh | grep 'ook' >> ook.out | grep 'eek' >> eek.out Where ...
1
vote
1answer
695 views

grep searchstring /etc/crontab strange behavior in BASH script

I am working on a BASH script which creates automated backups via the crontab. I am trying to use myVARIABLE=`grep backup /etc/crontab` to return lines containing "backup" if an entry has already ...
7
votes
3answers
9k views

How can I find all files that do NOT contain a text string?

What concise command can I use to find all files that do NOT contain a text string? I tried this (using -v to invert grep's parameters) with no luck: find . -exec grep -v -l shared.php {} \; ...
5
votes
6answers
9k views

Recursive search doesn't work for grep on solaris

On our Solaris server I'm finding that grep -r doesn't work, which is the usual way that I use grep. It seems that egrep has the same behavior. Given that I have no control over the machine, is there ...
9
votes
11answers
9k views

How can I “cat” a file and remove commented lines?

I'd like to know if there is a way that I could cat file like php.ini and remove all lines starting with ; For example, if the file contained this: ; - Show all errors, except for notices ; ...
10
votes
4answers
13k views

Grep: how to add an “OR” condition?

I am a total regex newbie. I find it confusing and I avoid it like the plague (wanna take some guesses as to why I'm not good at it?). But I suspect it might be the solution to my question. Which ...
4
votes
6answers
1k views

Grep a directory and return list with line numbers

I'm currently trying to learn more about bash scripting and all of that fun stuff, and I pieced together this little command: find $path | xargs grep -n $pattern | awk '{print $1}' While this DOES ...
2
votes
1answer
420 views

Getting data section with maximum element

I have some data stored in JSON-like format. { { value1: 14, value2: 12, value3: 1 }, { value1: 4, value3: -1 } } How can I get subsection ...
2
votes
2answers
1k views

How to treat a file as a single line with grep to apply a regexp search pattern?

I want to match everything that is between some lines with regexp but not this that match the start and the end. This sound to me as positive lookbehind and positive lookahead start text bla ...
14
votes
1answer
546 views

Grep alias - line numbers unless it's in a pipeline

I want to create a bash alias for grep that adds line numbers: alias grep='grep -n' But that, of course, adds line numbers to pipelines as well. Most of the time (and no exceptions come to mind) I ...
2
votes
3answers
892 views

How to cut the output to only gather the filename and get-parameter?

I have multiple files with multiple links that are formatted like this: <a href="http://example.com/fnord.layername.html?parameter=FOO-_-BAR-_-FNORD" class="poit"> <img ... /> ...
5
votes
2answers
5k views

Looking for a Java class in a set of JARs with find, unzip, grep

I was trying to find the JAR containing a Java Class. JARs are in zip format. My first attempt was: $ find -name "*3.0.6.RELEASE.jar" | xargs -l1 unzip -l \ | grep stereotype.Controller ...
4
votes
1answer
1k views

How can I match the page break character in a regular expression?

Nano calls it ^L, but of course, typing something like $ grep -v "^\^L" file doesn't work. Its unicode codepoint is 000C. How can I match it in a regular expression?
25
votes
4answers
65k views

count number of lines, bash grep

Hello I am grepping results to file, and then doing cat to show its content on the screen, I want to know how many lines of results I have in my results file and the += it to some counter. What will ...
3
votes
2answers
7k views

Search string in many files on HP-UX

I need to find which files (they can have space in the filename) of a directory contains a string using only sh and system's commands (Perl is not an option). For a few files, this command works ...
1
vote
2answers
3k views

Why does adding a colon break this grep pattern?

I executed a search with grep, but it doesn't work like I expected it to. I have the following lines in a file: blacklists/redirector/domains:needyoutube.com ...
2
votes
2answers
10k views

Finding files containing certain strings under a directory [duplicate]

Possible Duplicate: How do I find text within a file and have it search multiple subfolders? I would like to find out all the files under mydir/ directory whose content contains the string ...
1
vote
1answer
2k views

How to filter wvdial/pppd terminal output

I use wvdial to connect to the net with with my USB modem. It works correctly, and I am quite happy with it. When I start it in XFCE I have it set to output to a borderless, transparent terminal so ...
1
vote
2answers
554 views

pattern search and display the last occuring pattern?

I have a log file containing startup and shutdown times for everday. I want to see the last pattern pattern for startup and shutdown(which is located at the end of the file being updated everyday). ...
3
votes
1answer
1k views

How to use a value returned by a script in grep filter?

I'm on FreeBSD's csh. I want to form a row with domains of one user and then use this row to filter exim maillog to get only mail from/to this user's domains. I wrote a script to form a row from a ...
10
votes
2answers
40k views

Return only the portion of a line after a matching pattern

So pulling open a file with cat and then using grep to get matching lines only gets me so far when I am working with the particular log set that I am dealing with. It need a way to match lines to a ...
2
votes
3answers
1k views

Returning only the portion of a line after a matching pattern

I have a file (file_name) which contains exactly one occurance of the string Result:, at the start of a line. I want to print all the characters after the string Result: in that line until I encounter ...
3
votes
4answers
631 views

Find a string (like grep -q) within only a section of a file

I want to write some Bash that can verify that a string exists in a configuration file. I can't change the file format, it belongs to a different application. The file is subdivided into groups named ...
-2
votes
1answer
299 views

Linux “rpl” command doesn't replace text [closed]

I'm using rpl program in linux to replace date( with pdate( in some files. But it says A Total of 0 matches replaced in 1 file searched. while grep output for date( is: ...
4
votes
2answers
782 views

grep caret appears to have no effect

I was under the impression that a caret symbol means "beginning of the line" with Extended POSIX regular expressions. However, when I use it with grep it behaves unexpectedly. #grep --version GNU ...
2
votes
2answers
1k views

How do I show all files in a directory except those that have a certain extension AND display them in multiple columns?

Since I write in Python a lot it's kind of annoying to see .pyc files all the time and I would like to just hide them at this point. I tried the following, but I can't seem to figure out how to get it ...
3
votes
1answer
590 views

grep and brackets in text

I store downloaded files in a log like this: [source] filename To avoid downloading a file more than once I grep for [source] filename before: if ! grep "$signature" downloaded.log > ...
0
votes
1answer
376 views

What does ^> mean in a grep pattern?

What does this command do? grep "<[^>]*>" inuux.xml What is searching for?
5
votes
1answer
2k views

What does \bi\b mean in a grep pattern?

What does this command do? grep "\bi\b" linux.txt What is it searching for?
4
votes
3answers
2k views

Show lines matching a pattern and the 4 lines before each

For example, from this file: CREATE SYNONYM I801XS07 FOR I8010.I801XT07 * ERROR at line 1: ORA-00955: name is already used by an existing object CREATE SYNONYM I801XS07 FOR ...
1
vote
1answer
2k views

grep directory names, filenames, and contents all at one?

I'm writing a module for drupal. Its functionality is contingent on the directory name, certain file names, and function names being identical. I'm troubleshooting now, and I wanted to to a search ...
1
vote
2answers
1k views

How to group grep results?

I have a file that contains results grouped into categories. For example: checking results for $var here are some results1 for $var status ok here are some results2 for $var status ok here are some ...
1
vote
5answers
954 views

Display output to console while grep is used

In vim I use the following command to compile a tex file: pdflatex\ \-file\-line\-error\ \-shell\-escape\ \-interaction=nonstopmode\ $*\\\|\ grep\ \-P\ ':\\d{1,5}:\ ' this works in terms of getting ...
1
vote
1answer
2k views

grep - recognize carriage return as new line [closed]

I want to search a webserver running unix for php-files containing a specific string. Usually I use these commands to accomplish this: find . -name "*.php" -print0 | xargs -0 grep -H -i "the string ...
2
votes
3answers
232 views

Omitting results containing '//' from grep searches

I'm trying to search a substantial C++ codebase for a single line that is outputing text to the terminal that I'd like to suppress. I have grepped for std::cout and have had around 40 different files ...
4
votes
2answers
6k views

Grep 'OR' regex problem

I am trying to use grep with a regex to find lines in a file that match 1 of 2 possible strings. Here is my grep: $ grep "^ID.*(ETS|FBS)" my_file.txt The above grep returns no results. However if I ...
0
votes
1answer
345 views

Printing file content with grep

Is it possible to print to the console all file content using only grep command? (wihtout cat, less, echo, more...)
5
votes
1answer
537 views

How can I search/browse in some process's memory?

I'm using MacOS X 10.7 and I'm not very familiar with unix. Is there a command for a search in some process's memory for a string?
1
vote
1answer
185 views

What special characters does grep parse by default? [duplicate]

Possible Duplicate: In a regular expression, which characters need escaping? I know there is the -E flag which treats the "search term" as a regular expression. However, it seems that even ...
12
votes
3answers
850 views

How can I redirect matching lines to a file, and non-matching lines to a different file?

Is there a script/program/utility already available for the following requirement in a optimised way? someCommand | tee >(grep "pattern" > LinesWhichMatch) | grep -v "pattern" > ...
6
votes
6answers
18k views

How to search for a word in entire content of a directory in linux

need to search for something in entire content I am trying: find . | xargs grep word I get error: xargs: unterminated quote How to achieve this?
11
votes
3answers
7k views

How to show lines after each grep match until other specific match?

I know that by using the "-A NUM" switch I can print specific number of trailing lines after each match. I am just wondering if it's possible to print trailing lines until a specific word is found ...
1
vote
1answer
833 views

Diff similar lines

I'd like to print a list of lines where the first word in two files is identical, and the rest of the words are not. Some complicated mess with comm, grep and cut would be possible, but hopefully ...
1
vote
2answers
1k views

Using grep to read a paragraph on Solaris

How can I grep a paragraph from a file in the Solaris operating system? I tried the -p option used in AIX, but it's not useful in Solaris. grep -p Accept is not working in Solaris. Is there any other ...
8
votes
3answers
5k views

How do I grep without leading whitespaces?

I'm greping through a large codebase, and leading whitespaces and tabulation seem to be quite annoying. Is there any way to get rid of it? grep -R "something" ./ E.g, instead of: foo/bar.cpp: ...
24
votes
2answers
13k views

How do I pass a list of files to grep

I am using find and getting a list of files I want to grep through. How do I pipe that list to grep?
2
votes
2answers
88 views

How do I execute a command on a given string in each line of a file?

Let's assume that I already have a file created. This file creation comes from the execution of a command. The contents of the file will be up to 4 different lines looking something like this: LUN ...
13
votes
4answers
5k views

What makes grep consider a file to be binary?

I have some database dumps from a Windows system on my box. They are text files. I'm using cygwin to grep through them. These appear to be plain text files; I open them with text editors such as ...
1
vote
3answers
477 views

Use “grep” to match text in multiple files

I have data in multiple files. I want to find some text that matches in all files. Can I use the grep command for that? If yes then how?
3
votes
3answers
2k views

executing multiple greps in a single find command

I want to use find command to find some files containing multiple patterns at the same time. I tried something like this: find . -name "*.xml" -exec grep -iH keyword1 + && grep -iH ...