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

learn more… | top users | synonyms

4
votes
6answers
5k 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 ...
2
votes
1answer
37 views

Globbing fails in zsh, but works in bash

I have an alias in bash, that I'm trying to port over to zsh. I thought it may have been the alias itself, but now it seems it's just the globbing. grep -irl --exclude=\*.{log,class,fuegoclass,dat}* ...
1
vote
7answers
709 views

Can grep be used for searching files with some string in their names?

I understand that grep can only be used for searching for files which contain a string in their content. Can it be used for searching for files with a string in their names? I read the manpage, and ...
2
votes
1answer
76 views

How to find text in files and only keep the respective matching lines using the terminal on OS X?

I am pretty new to the terminal and command lines, from what I have found out grep seems to be the right tool for search files for specific text strings. I have a folder with many huge text files and ...
6
votes
4answers
744 views

Why doesn't grep using pipe work here?

I have the following command: find / -name libGL.so.1 Which returns lots of lines with "Permission denied". I want to exclude such lines, so I added the following: find / -name libGL.so.1 | grep ...
2
votes
2answers
170 views

Grep log and get text between log delimiters

Is there a way to grep a log and find text between the log entry delimeters? Our log file separates the line entry with characters "-------" So when I search the text word I want all the lines before ...
0
votes
1answer
75 views

Grep : Find all possible cases of a word in text file

I have a directory with many text files. Out of these files, I am interested in a word "abcdefghi". I need to list all possible cases of this word such as abcdefghi abcdefghI abcDefghi ABCDEFGHI ...
13
votes
9answers
13k views

How can I grep in PDF files?

Is there a way to search pdf files using the power of grep, without converting to text first in Ubuntu?
2
votes
3answers
66 views

Make grep work for special filenames

I have a set of txt files whose names may contain space or special characters like #. I have a grep solution grep -L "cannot have" $(grep -l "must have" *.txt) to list all the files who have must ...
2
votes
3answers
704 views

sed, grep, or tr command that returns only Latin characters from a UTF-8 file

I am working with the text of the 300 tang poems, which unfortunately is a single file containing both Chinese and English. Since I am interested in 'extracting' the English, I hope to use sed, ...
2
votes
3answers
7k views

Grep command to find files containing text string and move them

I am able to locate files in a folder containing a specific text string using this command: grep -lir 'string' ~/directory/* How do I move the files that appear in the above result to another ...
15
votes
4answers
43k 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 ...
1
vote
0answers
32 views

Filter partial output of some script [duplicate]

I need to analyze the output of some script So, I know their header and their tail of some part of the output script, but not the content. I found an approach [1] But I need something like: $ ...
1
vote
3answers
57 views

Detecting extension files doesn't executed for a period

How can I detect the ``.class` files in my workspace which haven't executed for a certain period, and remove them?
4
votes
1answer
64 views

Redirect grep out to a file does not work [closed]

I am doing a recursive grep by the following command: grep -r "load" . > tmp.txt However, when I hit enter, the command does not execute and bash is waiting for more inputs.. My OS is Ubuntu ...
16
votes
9answers
980 views

Grep lines but let the first line through [duplicate]

Consider the following output from df. Filesystem Size Used Avail Use% Mounted on /dev/sda1 23G 6.1G 16G 29% / udev 10M 0 10M 0% /dev tmpfs 397M 420K ...
1
vote
1answer
57 views

grep file from file

What is the fastest way to grep -v a file against another one, both line by line. does grep support this ? Or should I use it on two for loops ?
5
votes
2answers
201 views

Is there a archive of old man pages? specifically for the features available for grep in early 'ed'

This is just a bit of history rummaging... I'd like to know how different today's grep is to the original implementation, introduced by Ken Thompson in ed. which evolved to ex, which then became vi... ...
-1
votes
3answers
83 views

How can I run a grep on epub/mobi files?

Is there a way to do it, particularly on a set of multiple epub/mobi files in one directory?
3
votes
1answer
82 views

pcregrep newline lookbehind assertion bug?

Attempting to use pcregrep to print the first line after a blank line. For example, contents of file first line second line I need second line to be printed. Here are a few tests using the same ...
-1
votes
4answers
82 views

How to exclude directories from `ls -R` output?

If ls -aR | grep ":$" returns ./.hiddendir2: ./dir1: ./dir3: ./dir3/.hiddendir4: then how can you update the pattern given to grep so that you only get ./dir1: ./dir3: (note that the last ...
2
votes
2answers
130 views

grep print relative file path when doing a recursive search

I'm trying to find out which version of hibernate the project depends on (this is orthogonal to my question). We have a parent project with several sub projects, and I know this is defined in one or ...
16
votes
5answers
33k views

grep: count total number of occurrences

grep -c is useful for finding how many times a string occurs in a file, but it only counts each occurence once per line. How to count multiple occurences per line? I'm looking for something more ...
2
votes
4answers
122 views

Color matching but print other lines too [duplicate]

I have an alias: alias grep='grep --color=auto'. I wish to have some way to print not only matching row but all of them and just color matching patterns. I doubt is there an option to do that in the ...
0
votes
1answer
74 views

How many times does the same character occur twice in a row

My task is using grep to find how many times the same character occurs twice in a row. I was thinking about something like this but it isn`t working grep '[a-zA-z]{2}' *.txt | wc How can achieve ...
8
votes
6answers
375 views

How to get multiple lines out of a file by a regex?

How to get multiple lines out of a file by a regex? I often would like to get multiple lines / modify multiple lines by a regex. A example case: I am trying to read part of an XML/SGML file (they ...
0
votes
2answers
227 views

How can I use grep to search multiple unnested directories?

It may sound like I'm asking the same thing as this question, but I have different requirements. This is an example of my filesystem: /code/ internal/ dev/ main/ public/ dev/ main/ release/ ...
1
vote
2answers
70 views

Parse,Manipulate Data In linux/Unix

I want to have exactly the same output in this post(http://unix.stackexchange.com/questions/126139/extract-data-in-linux-unix)as above,but I have a new input file,which is below: ABCB11 4 ACE 11 ...
1
vote
2answers
164 views

Extract data in linux/unix

I have input data which I want to parse and extract values using awk/grep/sed: group-2 9 10 text color=black,from=ABCB11,fromid=4,order=2,thickness=3,to=ACE,toid=11,use=1,z=1 group-3 0 1 text ...
2
votes
1answer
233 views

Regex doesn't work with grep

I have a string like this TEST="/dev/sda1 on /media/sda1 type vfat (rw,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=iso8859-1,quiet)" (Result from mount | grep sda1) ...
0
votes
2answers
130 views

Compare first column in different files

I want to compare one file with other files in the same directory. file1.txt contains: move 34#123# get 11#278 put 33#29#567#23 file1.txt should compare with files 1.txt and 2.txt. 1.txt ...
4
votes
3answers
75 views

How to find files containing two strings in different lines

A real example is: I have a Python file util.py, and I changed one of the function name from foo to bar. There might be other files using foo as function name and they are irrelevant. I want to ...
1
vote
3answers
402 views

How to specify matching patterns while excluding some files having a PATTERN in their filenames

NOTE: I have updated this question from what I posted earlier and hence some answers may not match with what I intend to ask. I want to search some TEXT in a set of files in sub-directories and ...
7
votes
1answer
158 views

Grep search returning a different line

This is my grep search grep 'Invoker_Slark*' true_pairscore.txt But it returns the line Invoker_Slardar. Even though the file contains Invoker_Slark. Why is that?
0
votes
6answers
74 views

grep, display only files starting with . (hidden)

I tried to display only hidden files but dont know how to do it. That is working(but matching also dots in other places) ls -la | grep '\.' Was trying adding ^ but didnt find soultion.
1
vote
3answers
136 views

how to pipe the output of cut to the foreach command?

I have the cut command I want that grabs the first word in each line of a file. I then want to put each word from the cut command into a foreach. I then want to do a grep command inside the body of ...
4
votes
4answers
402 views

How to exclude some files not matching certain extensions with grep?

I want to output all lines containing the word OK recursively from a directory. But there are a few extensions which I need to exclude from the result: *~ *.map *.js except *.debug.js I tried: ...
3
votes
4answers
144 views

Identifying genes from a list of genes

I have a gene list file. Some thing like this SWT21 SSA1 NRP1 EFB1 TFC3 MDM10 I have another file which also contains the names of these genes in my list along with other ...
3
votes
3answers
179 views

Rearrange text file by prepending data rows with header row

I have a file whose content looks like this: 2009 150 0 0 0 0000 75.316 0.0400390625 0.00007 0.00000 0.8980 76.216 0.0400390625 0.00007 1.00000 0.9046 77.217 0.0400390625 ...
2
votes
4answers
253 views

Can I use grep matches to execute command? CentOS

I need to upgrade php from 5.3 to 5.4. I've installed it with rpm. I want clean install: delete all 5.3 packages, and install all necessary 5.4. Here is the command to see all installed packages: rpm ...
25
votes
3answers
2k views

Does grep use a cache to speed up the searches?

I have noticed that subsequent runs of grep on the same query (and also a different query, but on the same file) are much faster than the first run (the effect is easily noticeable when searching ...
3
votes
2answers
613 views

Using grep/sed/awk to classify log file entries

I need to process a very large log file with many lines in different formats. My goal is to extract unique line entries who have the same starting pattern, e.g. '^2011-02-21.*MyKeyword.*Error', ...
4
votes
4answers
433 views

Detecting pattern at the end of a line with grep

If I do: $ ls -R .: 4Shared/ Cloud/ ./4Shared: UFAIZLV2R7.part3.rar ./Cloud: UFAIZLV2R7.part2.rar.part UFAIZLV2R7.part1.rar.part UFAIZLV2R7.part4.rar.part If I want to list the .rar files only, ...
2
votes
4answers
99 views

Find + Grep Recursive Search

I am mirroring a website using wget. On the server, there is a dump of the find / command, which includes filenames in the form : /dir1/ /dir1/page1.txt /dir1/page2.txt ... The mirrorring is very ...
0
votes
2answers
80 views

Extracting with grep/sed a first pattern and then a second pattern that occured some lines before and related to the first

I'm trying to extract a specific line from a .htm file when a pattern occur ("Event 100" in my example below) but at the same time I need to retrieve also another pattern which is related to the first ...
2
votes
3answers
142 views

How can I get the last line number of unique commands when grepping my history file?

I rely on my history file for previous commands, especially ones that are long with many parameters. Once I find the command and its line number(nn) I use !nn to run it. I prefer to see the full ...
1
vote
2answers
87 views

grep --byte-offset doesn't give me the bytes offset?

I run grep -b --byte-offset 'EXTH' Agent_of_Change.mobi but I only get "Binary file Agent_of_Change.mobi matches". How can I get the bytes offset instead?
1
vote
1answer
137 views

grep: match pattern on a particular position

I need to match a pattern with grep, only if it starts at position 16. Lets suppose I want to match the string ' pattern' (starting with space) the following should match bla bla bla bla pattern ...
2
votes
1answer
98 views

How to print strings matching a pattern with grep?

I want to get a list of strings matching the following pattern: CLASS_NAME:"*" where * represents any number of characters. I tried: grep -o CLASS_NAME:\".*\" script.js and grep -o ...
3
votes
4answers
260 views

extract the characters before () using grep

I need to extract the characters before the character '('. My file structure is: rose(good)ook daisy()no lilly(bad)fine sunflower()nice I need output file as in the form of: rose ...