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

learn more… | top users | synonyms

0
votes
2answers
26 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
41 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
4answers
76 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
134 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?
4
votes
4answers
193 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: ...
1
vote
3answers
10 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 ...
-1
votes
0answers
19 views

Rearranging text file with blocks of data [duplicate]

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 ...
3
votes
4answers
138 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
162 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 ...
4
votes
4answers
161 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
59 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
6answers
51 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.
0
votes
2answers
56 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
36 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
33 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
30 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
38 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
202 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 ...
1
vote
3answers
36 views

Detecting extension files doesn't executed for a period

How can I detect the .class files in my workspace which doesn't executed for an determinate period, and remove it?
1
vote
1answer
52 views

Remove the string before the whitespace

I want to remove a word before the whitespace. My file structure is: ant tiger static rabbit lion dynamic monkey donkey I need the output as: ant tiger rabbit lion monkey donkey ...
0
votes
4answers
55 views

bash event not found trying to match and exclude parenthesis in grep

In a very long line I'll summarize with: (foo),(bar,baz(word,right),(end) I want to print only: (bar,baz(word,right To match the second parenthesis, I exclude the word that follows the ...
1
vote
3answers
59 views

Extract part of string using grep

I have 3 files in a directory MYO144064T MYO144064TA MYO144064TX Where the digits and 11th character will change. In my csh script, I want to extract the letters 'A' and 'X' probably using grep ...
3
votes
1answer
69 views

What's the difference between \b and \< in the grep command

In the man page of grep, I see The symbols \< and \> respectively match the empty string at the beginning and end of a word. The symbol \b matches the empty string at the edge of a ...
3
votes
2answers
114 views

To grep 20 characters after and before match

I have the problem that I get too much information after the match for grep -RnisI --color=auto "pseudomonas" * I want to get only like 20 characters or 10 words after and before the match. What ...
0
votes
1answer
28 views

echo keywords found

I'm trying to figure out which keywords are being found for [each] file in the script below. I tried adding echo $keywords and it just outputs every keyword. Code: keywords=("Alachua" "ALACHUA" ...
6
votes
6answers
352 views

bash find lines starting with string

I have a bunch of files and I want to find which one contains sequential lines starting with a certain string. For example for the following file : Aaaaaaaaaaaa Baaaaaaaaaaa Cxxxxxxxxx Cyyyyyyyyy ...
3
votes
4answers
136 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 ...
2
votes
1answer
61 views

make grep confirm all matches

I am writing a "unit test" for a bunch of .tex files and want to check for incorrect entity names, e.g. "Data Items" instead of "DataItems". Currently, I use grep to search for the incorrect ...
4
votes
4answers
99 views

Grep for range of numbers [duplicate]

How would you search a log file for a date range? Log file looks like this: 01/14 00:00:01 INFO: received connect request from 10.10.10.10 I need to condense the log to 10 minutes starting ...
2
votes
4answers
121 views

grep change of line followed by a variable

I have a file of the following form (with '!!!!!!!!!!!' serving as delimiters), and I want to find the appearance of a number only when it follows a delimiter. I suppose it's a concatenation of grep ...
0
votes
2answers
47 views

How to search '(+1)' character substring in a string

I want to search for (+1) in a string (which is a GDG dataset name to confirm if it is a GDG) and want to get a binary answer if it has (+1) as part of the string or not. Can some one please help?
2
votes
2answers
106 views

grep and directories containing spaces

I would like to search all files containing an association of strings (here the files should contain 'arthur' AND ('déni' OR 'deni') for instance) in a directory and subdirectories. After some search ...
2
votes
5answers
90 views

identifying words in file 1 and matching them to second file and printing them

I have two files as follows File 1 has list of Ids ram Tarah taikah jhdfklj File 2 has id=ram;*between*hkjhdswklf kjsdklhglshglkhgklsdgkhdfg id=taikah;jhdjfkhg**kjdfkjksfdjk ...
2
votes
2answers
171 views

filter and count with grep in a single pass?

I am using grep at the end of a set of piped commands to filter some rows out of a file. Afterwards I will want to do some arithmetic based on the number of remaining rows. e.g. ...
1
vote
1answer
76 views

Can we make grep faster by indexing words in files? [duplicate]

Over a decade ago I imagined an improved version of grep that would use indexes to make recursive searching faster. I never got around to writing it, but I wonder if somebody else did! My original ...
1
vote
1answer
92 views

grep ipaddress in expect script

this is part of code, expect script and I have problem with greping ipaddress from file wich is assign to variable $filename.This is the code: #!/usr/local/bin/expect -- ###Made by Etihkru#### ...
0
votes
4answers
62 views

Grep searching for files which are not existing

I wanted to search for the text " Starting kernel" in a directory, so I did this: [root@xilinx petalinux-v2013.10-final]# grep -r "Starting kernel" grep: warning: tools/packagemanager/lib/i686: ...
2
votes
3answers
50 views

How to list backup files missing corresponding real files?

I accidentally deleted some files spread across my home directory, but I do not know exactly which ones were removed. How can I get a list of all backup files missing their corresponding file? ...
4
votes
3answers
87 views

Search for specified keywords in files and copy to a new filename based on the keyword

I'm trying to create an .sh script where if any keyword is found in a file then copy that file to the directory /pathtofolder/keywords/$thefirstkeywordfound (overwrite the file if it already exists). ...
3
votes
2answers
131 views

How to use restricted characters in egrep?

I'm trying to use a regex in egrep on Centos 5.10, based on the one I made from this question on SO. T12345 .{1,100}[\n\r].{1,100}2014.03.04 I can successfully match the regex to the content in my ...
3
votes
1answer
94 views

Is there any drawback to using “grep -E” instead of plain “grep”?

I understand that GNU grep without -E uses basic regex and that grep -E uses extended regex. Is there any harm in using grep -E even for situations that would work with plain grep?
2
votes
4answers
92 views

Compare two text files and find matching lines

I have two files A and B. A looks like this (4 to 6 lines): GAGA CAGA GGGT TATT file B is a really big file with thousands of lines, here is a short example: AAATGTCAAGAGACAGAAATGTCAAGAGGGT ...
1
vote
2answers
35 views

Egrep multiple strings in an XML file

I have a collection of XML files in a standard format that I'd like to search to see if they match two strings. Here is the idea: <ELEMENT1>Dave</ELEMENT> ...
6
votes
2answers
187 views

What's the most efficient way to grep for two completely separate things and assign the values to separate variables?

CentOS 6.x I want to take the output from curl, grep for two completely separate strings, and assign their respective values as variables. What is the most efficient way to do this (without writing ...
4
votes
2answers
221 views

how to make alias to make grep command shorter [duplicate]

In my coding, I always do grep -rnIi "abcabc" . --color But, how to make an alias that can let me type only one word with my search string? Is that possible?
1
vote
2answers
83 views

Redirect grep error output to file

I wanted to capture to a file the errors being returned on the command line from grep. For example, grep foo.lookup No such file in directory I want to output that to a log file. This is my shell ...
-1
votes
2answers
49 views

How to extract submatches from a string and write those to a file?

I want to parse a string for specific submatches and output those - one submatch per line - into a file. Essentially I would like to extract the value of each href-attribute: $ cat Fin <a ...
0
votes
2answers
88 views

Using grep to find first two numbers of IP addresses?

I'm trying to figure out how to use grep to pull out only the first two numbers of an IP address in a list. I've got a routine that is isolating the log entires (from Exim) that I need, now I just ...
3
votes
2answers
126 views

Why pidof and pgrep are behaving differently?

I have a init script in /etc/init.d/myservice for initialize a service like this: ... start() { ... daemon /usr/sbin/myservice ... } stop() { ... pgrep myservice pidof myservice ps -ef ...
1
vote
2answers
50 views

Emacs temp dot hash file don't exist

I use find | xargs grep a lot when working on large source code and when I didn't save a file in Emacs it creates .#SomeFile and grep give error that there's not such file (I'm not including because ...