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

learn more… | top users | synonyms

2
votes
3answers
148 views

grep on a Java Method

Lets say I have a java class called DirectAction some of the methods in the class have the word "action" or "Action" What is the grep command to get the names of all the methods who have "Action" or ...
6
votes
10answers
1k views

Copy only Specific text of a file to another

I have a file abc.txt the contents are <classpathentry kind="src" path="Sources"/> <classpathentry kind="con" path="WOFramework/ERExtensions"/> <classpathentry kind="con" ...
0
votes
4answers
304 views

Search for a Value only in one column w.o using awk, sed, or perl

I have a file that looks like this : Marketing Ranjit Singh FULLEagles Dean Johnson Marketing Ken Whillans FULLEagles Karen Thompson Sales Peter RobertsonPARTGolden ...
1
vote
3answers
141 views

Returning only the portion of a line after a matching pattern (Unix)

I have a parent folder (abeps) which contains several sub folders (1,2,3....25) where output file is located, one in which - all are the same name (opt.out). In this files there is an unpredictable ...
1
vote
2answers
233 views

How to show specific lines from specific columns of a file

First off, I'm not allowed awk, sed or perl. For my assignment I was given a file of employee list: Marketing Ranjit Singh FULLEagles Dean Johnson Marketing Ken Whillans FULLEagles ...
2
votes
3answers
192 views

conditional coloring in grep

I have a simple bash script. One line of my script matches a "pattern" with grep and colors the match grep -i --color=always -- "$1" I need to modify it, so that it only colors the match, if the ...
5
votes
3answers
2k views

Recursive grep vs find / -type f -exec grep {} \; Which is more efficient/faster?

Which is more efficient for finding which files in an entire filesystem contain a string: recursive grep or find with grep in an exec statement? I assume find would be more efficient because you can ...
0
votes
1answer
100 views

Duplicate specific text in text file, using perl or grep

I need to duplicate part of a plain text file as follows: The text file consists of a sequence of "pages", of the form: <page [lots of lines of text] /page> <page [lots of ...
4
votes
1answer
152 views

Blank lines when executing “grep | xargs” in a “find -exec”

I'm trying to list all directories of a web server that are blocked by Apache via a .htaccess (containing deny from all). I've managed to get the list of blocking .htaccess but when I try to extract ...
3
votes
2answers
85 views

how to grep complex hierarcy?

I have a file as:- start apple 1 a 2 b 3 c start orange 4 a 5 b start mango 1 a start a/b/c 5 z end 4 b end 6 c end start banana 3 c end 4 d 5 e end I want the output as :- 1 apple/a 2 apple/b 3 ...
4
votes
6answers
7k 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
67 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
1k 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
110 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
1k 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 ...
3
votes
2answers
348 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
98 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 ...
14
votes
9answers
15k 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
81 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
740 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
10k 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 ...
21
votes
4answers
56k 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
33 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: $ ...
4
votes
1answer
82 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
1k 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
80 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
220 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
135 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
132 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
241 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
356 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 ...
17
votes
5answers
43k 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
174 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
104 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
699 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
1k 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
73 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
174 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
364 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
423 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
104 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
1k 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
169 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
117 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
377 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
1k 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
167 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
230 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 ...
26
votes
3answers
3k 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
659 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', ...