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

learn more… | top users | synonyms

7
votes
3answers
5k views

grep: Trailing backslash

I want to do a grep for \resources\. How do I do this? I've tried: grep \resources\ grep \\resources\\ grep "\resources\" grep "\\resources\\" None of these work.
9
votes
4answers
6k views

I would like to grep all files except some file types?

How do I recursively grep files within a given folders except a couple file types? For example, I'm looking for a string within my workspace folder but it ends up searching inside sql files and ...
9
votes
2answers
267 views

“Grep breaks, causing the boot process to hang forever”

Question within a question (from the Debian wiki): Should I use sid on my desktop? If you think you can handle a broken Debian system, sure. Do you know what to do if libpam0g breaks, ...
0
votes
1answer
71 views

grep *stringA*[number]

I was wondering how can I grep an expression of the type *stringA*[number] In other words, I want to target lines that have the following pattern: anything + stringA + anything + [number] For ...
7
votes
3answers
9k views

How can you move (or copy) all files of a certain type to a directory in Unix?

I'm not very familiar with all the tricks of grep/find/awk/xargs quite yet. I have some files matching a particular pattern, say *.xxx. These files are in random places throughout a certain ...
3
votes
1answer
875 views

git grep colors differ from grep custom colors

I've setup grep colors in my ~/.bashrc : export GREP_COLORS='ms=01;34:mc=01;34:sl=:cx=:fn=35:ln=32:bn=32:se=36' They work for grep --color=auto grep --color=always Unfortunately, those custom ...
2
votes
2answers
373 views

xargs grep suggestion

grep -v "\<Swap" instruments.log | awk '{ idx=index($0, "MasterId="); masterId=substr($0, idx+length("MasterId=")+1); masterId=substr(masterId,1,index(masterId,"L")-3); print masterId; }' | xargs ...
1
vote
1answer
911 views

Difficulty making a regular expression to find at least 2 occurrences of a character in a file

I have a file containing random codes. Each code has ten characters in it, and I am trying to grep codes in the file that have at least 2 occurrences of a character. I am doing this: grep DD* ...
2
votes
2answers
823 views

How can I retain the console input in mplayer when reading from stdin?

I'm playing around with the command line interface of mplayer. I'd like to script it in the following way find /some/path/ -type f | grep -vif blacklist | mplayer -shuffle -playlist - where ...
1
vote
1answer
2k views

How to grep a text recursively on BusyBox 1.0?

How can I find a file containing a certain string on a BusyBox 1.0, if grep -r does not work?
12
votes
11answers
8k views

Grep huge number of patterns from huge file

I have a file that's growing about 200,000 lines a day, and it is all formed with blocks of three lines as such: 1358726575123 # key Joseph Brunner # name carpenter # job ...
6
votes
1answer
397 views

How to detect and delete lines containing ˆ@

I have a simple problem: In my file, the are lines containing the string ˆ@ˆ@ˆ@ˆ@ˆ@ˆ@. I just want to delete all lines with this string, using for example the sed or grep commands. And I would like ...
3
votes
3answers
3k views

How to search and replace text in all php-files in a directory and it's subdirectories

I am looking for a shell script that recursively traverses all .php files in a directory and performs a search & replace of a particular text pattern. The search pattern is quite long ( > 5000 ...
1
vote
3answers
2k views

Command-line tool to search docx files

Is there a command-line tool to text-search a docx file? I tried grep, but it doesn't work with docx even though it works fine with txt and xml files. I could convert the docx to txt first, but I'd ...
1
vote
2answers
4k views

Using grep to match only a match group in a regular expression?

I need to set my keyboard layout with setxkbmap before launching Wine games, as I use Dvorak for typing and this breaks every game's controls. What I'd like to do is simply write a script that grabs ...
1
vote
4answers
551 views

grep seems to ignore --include

man grep says grep [OPTIONS] PATTERN [FILE...] . . . --include=GLOB Search only files whose base name matches GLOB (using wildcard matching as described under --exclude). ...
6
votes
4answers
3k views

Finding the ID of a process and killing it

When ever I need to kill a background process I do ps -e | grep <process_name> Which prints something like this 1766 ? 00:00:13 conky , Then I use the process ID to kill it like so kill 1766 . ...
3
votes
5answers
250 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 ...
0
votes
1answer
524 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 ...
6
votes
3answers
5k 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 {} \; ...
4
votes
6answers
4k views

Recursive search doesn't work for grep on solaris

On out Solaris server I'm finding that grep -r doesn't work, which is the usual way that I used grep. It seems that egrep is the same. Given that I have no control over the machine, is there a way to ...
9
votes
10answers
5k 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 ; ...
5
votes
4answers
8k 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 ...
3
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
363 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
892 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 ...
13
votes
1answer
436 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
795 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
4k 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
926 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?
7
votes
4answers
32k 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
5k 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
2k 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 ...
1
vote
2answers
4k 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
1k 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
385 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
984 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 ...
7
votes
1answer
14k 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
620 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
455 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
237 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
544 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
692 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
477 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
292 views

What does ^> mean in a grep pattern?

What does this command do? grep "<[^>]*>" inuux.xml What is searching for?
4
votes
1answer
1k 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
1k 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
1k 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
736 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
803 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 ...