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

learn more… | top users | synonyms

9
votes
3answers
2k views

Is there a 'rc' configuration file for grep/egrep? (~/.egreprc?)

I usually do some grep when developing, and there are some extensions that I always don't want to look for (like *.pyc). Is it possible to create a ~/.egreprc or something like that, and put some ...
4
votes
4answers
10k views

grep lines starting with “1” in Ubuntu

I try to search for lines that start with "1" using ls -1 | grep ^1* but it returns lines that do not start with 1. What I am missing here?
9
votes
2answers
672 views

“grep -r foo *” vs “grep -r foo .”

When using grep -r you could search in all files with either * or . and it seems to return the same thing but is it really the same? Let's say I search for "foo", then I could write grep -r foo * ...
-1
votes
2answers
2k views

Meaning of asterisk (*) in grep

[USERNAME@host ~] echo -e 'prdxxx\ndadxxx' | grep "da*xxx" prdxxx dadxxx [USERNAME@host ~] echo $SHELL /bin/bash [USERNAME@host ~] dpkg -l | grep -iw bash ii bash ...
0
votes
1answer
343 views

wget images with certain path

im looking to only grab images from a document with a certain path for example domain.com/uploads/287167/file_name.jpg only grab those with the uploads/number/filename im currently doing it this ...
3
votes
5answers
427 views

Print non-existent files from a pipe input

I have a directory of lots of .PDF and .JPG files. There should be a .JPG file for each .PDF with the same name. I'm trying to use a command to find .PDF files that doesn't have a .JPG file. My ...
4
votes
2answers
587 views

how to use grep for specific files?

for example I type ls -altr | grep "23 Dec" so it will show files for 23 Dec only and I want to use grep for them, like ls -altr | grep "23 Dec" | xargs grep -l "some_string" but this doesn't ...
3
votes
5answers
385 views

Search among the content of a large number of plain text files?

I have a directory with 1,242,276 plain text files on my external hard drive. They are totally unorganized with meaningless numbers as their file names. The reason for that is because they were ...
2
votes
2answers
1k views

extract last match from logfile till end

Using sed, grep, awk, or ruby, what's a simple way to find the last match of a string in a larger log file, and send every line following it (inclusive) to another file? Example: grep -A222 ...
1
vote
1answer
95 views

How can I find all matches of a string in a directory?

Using grep (or some other utility), is it possible to find all matches of a regular expression in a folder (searching the text of each file?) I want to find every match of the regular expression ...
0
votes
1answer
102 views

What does this “matching lines means”?

The grep manual says "By default, grep prints the matching lines.". What does this matching lines says. When I tried its prints the whole paragraph containing the pattern.
0
votes
1answer
2k views

grep the only first word from output with grep -P

I'm trying to grep username users |grep "^\b\w*\b" -P how to do it with grep?
0
votes
2answers
181 views

Sample file for grep

Can anyone please point to some good sample files that helps to learn grep. This is for academic use. It should be a large one so that students could understand its importance
2
votes
3answers
720 views

grep how to suppress display of non-matched file?

I am trying to find files containing a specific word using grep. There are many files in the directory (> 500) Command I run $ grep 'delete' * Output validate_data_stage1:0 validate_data_stage2:0 ...
1
vote
1answer
175 views

Display words in color

I am looking for a tool which takes a file in input and a word to search. It should display the file with color the words if it corresponds to the search. Like grep --colors but displays all the ...
3
votes
5answers
186 views

grep device name and look for next value :

I have this output from a find command: abc,10.11.13.14,def,1.2.3.4,geh,6.7.54.23 where abc,def and geh are device names and could be of any length and others are IP address belong to devices. ...
9
votes
3answers
4k 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 ...
2
votes
1answer
180 views

grep all words with specified length, without letter x

So I am stuck here: grep -E '^....c...c...$' shows all words with the expr I need. Now from this words I only need the ones that don't have a x. Who can help me?
1
vote
3answers
830 views

How can I use grep to search for lines that start with a certain character in bash

I want an alias ('ggg') that will look through my existing set of aliases and tell me all the ones that begin with g. I have a lot of g* aliases :) I tried this: alias ggg='alias | grep ^g' but ...
3
votes
1answer
948 views

Modify /etc/xdg/lxsession/LXDE/autostart before boot

I have some parameters that I would like to change in /etc/xdg/lxsession/LXDE/autostart, before it is run. I get the parameters from a grep command. I would like to feed them to the autostart file but ...
1
vote
1answer
223 views

solaris + fit egrep for solaris

On Linux machines I use this syntax, in order to match all VALID ip's. My question: what needs to change for egrep command in order to run the egrep on Solaris? According to egrep manual page "-o" ...
1
vote
2answers
222 views

How to find which files contain mentions of a wildcard image name?

What I am trying to do is do a search on my server to find which files contain mentions of images with a certain keyword in the filename but all I can figure out is how to find the filenams (not image ...
11
votes
2answers
5k views

How to run grep with multiple AND patterns?

I would like to get the multi pattern match with implicit AND between patterns, i.e. equivalent to running several greps in a sequence: grep pattern1 | grep pattern2 | ... So how to convert it to ...
3
votes
5answers
2k views

Output multiple files from a single grep?

I'm not very experienced in shell scripting, but I'm trying to understand how to grep for a pattern and for each file where there is a match write a file to disk that contains the matched line from ...
1
vote
1answer
869 views

Using grep command and backreferencing

This is a pretty basic question, but I can't get my head around it. I'm learning Linux and one of the questions i've been given is; *The word sentimentalment includes the same three characters ...
0
votes
1answer
1k views

Problem with using grep command with env variable containing special characters

I have a variable "abc" with value "xyz*!@#" in my unix account (ksh). I used export command to export this variable into the environment. When I use grep command as below env |grep xyz I get the ...
6
votes
2answers
5k views

How to return both file name and line number with find … -exec grep?

When using find, how do I return the file name and the line number when searching for a string? I manage to return the file name in one command and the line numbers with another one, but I can't seem ...
5
votes
5answers
3k views

Recursively search folder but exclude svn subfolder

I want to find all occurences of foo in a large file system maintained by SVN but I don't want to match anything contained in any .svn directory. I get immediate matches when I do grep -l -e 'foo' * ...
1
vote
3answers
2k views

Linux: Does find | xargs grep have limitations?

I've historically performed something like: find . 2>/dev/null | xargs grep -i something_to_find 2>/dev/null If my pwd is barfoo (/foo/bar/baz/foofoo/foobar/foobaz/barfoo) it finds matches. ...
2
votes
3answers
528 views

Regex/pattern matching problem to extract data

What is the best way to remove distances in the following lines and output cdv format. Can this be done reasonably easily on the command line? I'd like to avoid having to write a full-blow script. ...
4
votes
4answers
440 views

Most efficient grep method

Currently I am grepping data from a file containing any of the following: ...
2
votes
3answers
501 views

Extract integers enclosed in round brackets

I'm new to Linux. I've a file which contains list of movie names and their release year. I want to list out all release years. Specifically my file looks like below TDKR(2012) Vicky Cristina ...
2
votes
2answers
482 views

Parse apache logs to exclude IP ranges

I need to look for some requests in a huge pile of apache logs. My only requirement is this: I need to only view the requests coming from any IP address that is NOT included in a list of 50 IP ranges ...
7
votes
2answers
442 views

When is it useful to use “grep — SOMEPATTERN”?

So under Linux/AIX where ever.., when is it useful to use: grep -- SOMEPATTERN the Question is the "--" part. When is it usefull to use?
2
votes
4answers
2k views

How to detect dos format files in git bash

Git Bash is a nice bash shell you get in Windows as part of the installation of Git. It comes with other typical unix tools bundled inside, such as grep, sed, awk, perl. It doesn't have the file ...
3
votes
1answer
3k views

The simplest method to count lines matching specific patterns, including '0' if line is not found?

I have very big logs (several gigabytes per day), that can (but do not need to) contain specific lines. I have to count the number of occurences of every one of these lines on a daily basis. I have a ...
4
votes
3answers
750 views

Delete the matching line and several more from a file

I have a text file called file_a.txt. My first command is grep -A 12 ".production =" file_a.txt The output is a few block. Each block of string contains 13 rows I specifically want to delete all ...
2
votes
5answers
80 views

Generate “item tag” pairs from “item,item,…|tag” lists [closed]

The characteristics of the input data: Each line consists of two fields, separated by a pipe '|', where the first field is a comma-separated list of items, and the second field is a tag. Input ...
2
votes
3answers
448 views

Which is a better way to search- find with regex or find with grep?

Of these two ways of searching a file recursively in all the subdirectories, which is faster / better ? find . -regex ".*/.*abc.*" or find . | grep ".*abc.*"
11
votes
6answers
504 views

How can I grep a directory based on the contents of two successive lines?

How can I grep a directory for lines that contain "Foo", but only get matches when the next line also contains "Bar"?
2
votes
2answers
170 views

How can I enhance the output of find and grep?

I really don't look forward to having to do find/grep because the output, as returned by find . -exec grep sometext {} \; -print is just not very easy to read even when you dump it in a file. What ...
3
votes
3answers
5k views

How can I pass strings with single quotes to grep?

My desired outcome is the following: to recursively search a directory looking for a given string in all found files. The following command is my usual port of call: find ./ | xargs grep -ns 'foobar' ...
1
vote
3answers
3k views

bash merge 2 lists removing duplicated

I have an embedded linux system using Busybox (OpenWRT) - so commands are limited. I have two files that look like: first file aaaaaa bbbbbb cccccc mmmmmm nnnnnn second file mmmmmm nnnnnn ...
3
votes
2answers
419 views

how to grep for c:\

I'm using cygwin's grep to find all instances of hardcoded paths on c drive. doing: grep -r "c:\\" . gives grep: trailing backslash Does anybody know how I can do this?
3
votes
3answers
1k views

Average rows with same first column

Given a file with two columns: Id ht 510 69 510 67 510 65 5l0 62 510 59 601 29 601 26 601 21 601 20 I need a way to coalesce all rows with the same ID into one that has an average height. In this ...
3
votes
4answers
1k views

Why does grep not work with redirection?

Using the top command with redirection works fine: top > top.log Now I want to use grep to filter a certain line: top | grep "my_program" > top.log But the log file will remain empty. But ...
2
votes
5answers
1k views

Need to grep file with specific letter and move to another folder linux

I need to select files which contain "Error" or "traffic" in their names, e.g. abc_ERRor.csv raError.csv bsn_Error.csv bbbctraffic.csv ccc_traffic.csv ... and move them into corresponding ...
6
votes
3answers
15k views

Searching for a string on multiple zip files.

I have a folder that contains about 200 zip files. Each zip file contains only one text file in it. I would like to search for a specific string in all the text files in all the zip files. I tried ...
4
votes
3answers
374 views

Use command grep and locate

How I can make the grep command locate certain words in the files specified by the routes found by the locate command? locate my.cnf | grep user (I want that grep command search the word "user" ...
3
votes
1answer
164 views

grep for n or more periods on a given line

I want to be able to arbitrarily match lines that contain a lot of periods, like this: $ echo "there's. someone on the wing. some. thing." | grep -stuFF [[:idunno:]]{4,} there's. someone on the wing. ...