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

learn more… | top users | synonyms

2
votes
2answers
1k views

Some UTF-8 characters not being recognized by grep or sed

Trying to determine all characters in a file. The file sample consists of: a eɪ abandon əˈbændən ability əˈbɪləti able ˈeɪbəl able ˈeɪbl abortion əˈbɔrʃən abortion əˈbɔrʃn about əˈbaʊt above əˈbʌv ...
0
votes
1answer
978 views

if condition, loop in grep [closed]

Could someone please provide help for me. I tried to start writing a shell script but am getting hung up with this issue. I need to grep commands "adb shell ps" and find in it 3 processes with names: ...
1
vote
2answers
383 views

Grep a string from file

I have 5 filenames created inside a folder for one operation.The filenames are in the following format. ES_currentdate_currenttime_processid_uniqueid.log I want to read the status from the latest ...
3
votes
3answers
12k views

How to find multiple strings in files? [duplicate]

I use the following command to find files with a given string: find /var/www/http -type f | xargs grep -iR "STRING1" But how can I find files which include "STRING1" OR "STRING2" OR "STRING3"? ...
3
votes
3answers
3k views

Grep in couple thousands files

I have directory with cca 26 000 files and I need to grep in all these files. Problem is, that I need it as fast as possible, so it's not ideal to make script where grep will take name of one file ...
4
votes
5answers
2k views

grep for multiple strings in files, and then list the files in the order of size

I am in a folder with lots of .txt file, I would like to find all the files which contain both stringA and stringB (not necessarily on the same line), then list these files in the order of the size ...
5
votes
1answer
2k views

Piping search term (not filename) to grep

I want to pick out certain lines containing a given number from a file. The file I want to search is called os_clusters/piRNA_clusters.bed. awk '{if (a[$0]++ == 0) {split($0,b,"."); ...
4
votes
2answers
194 views

Printing lines from one file if part of them appears in another. Both files are millions of lines long

I have two files, let's call them 123.txt and 789.txt. 123.txt is 2.5M lines long, and 789.txt is 65M lines long. Is there any way to use grep or similar to keep any lines from 789.txt that contain ...
4
votes
3answers
1k views

How to find first match in multiple files

Is there a way for the find command to search for the first match or occurrence of a string or pattern within each of multiple files? I've been using the usual syntax: find dir -iname '*.ext' -exec ...
1
vote
4answers
75 views

Extract data from line and prepend to the line?

Ok, I have some data in the form: <a href="/praha/jaktovidi/_zprava/jak-to-vidi-rektor-richard-hindls-5-cervna--1220102"> <a ...
1
vote
2answers
161 views

Tell a regex expression to skip the beginning of a line before matching

If I had a string like 45mb ./aaaa/bbbb/cccc/dddd and I use a regex like [^\/]*\/ it will match 45mb ./aaaa/bbbb/cccc/ I only want it to match ./aaaa/bbbb/cccc/ but I can't figure out how to do ...
1
vote
4answers
542 views

using simple regex quantifier expression in grep

Does anyone know why ls | xargs -n 1 basename | grep -E '[0-9]{1}' does not only show occurrences of a single digit between 0-9? For example if I have: touch 1 touch 22 touch 333 touch test_file ...
1
vote
1answer
59 views

How to use GNU tools to extract and merge two substrings of the same string?

Suppose I get the following result after doing a grep "emailed" /home/John/logs/2013-07-10.171222-0400EDT.html:I have emailed Mark. Thanks I want to extract the date from this so that my output ...
3
votes
2answers
278 views

How to grep recursively in order of last modified time?

grep -r does a recursive search in all files in a particular directory. However, if I want these files to be read by grep in the order of their last modified time, how do I do that?
1
vote
1answer
88 views

grep curly-bracketed entries from text file

I have a file with many curly bracketed words, ex. {test1}, {test2} - how would I grep for these words and output a distinct list of them? output example: {test1} {test2} I've tried this which ...
1
vote
3answers
163 views

Cat 2 files and avoid duplication of lines

I have the file1 with the following content {"name":"clio5", "value":"13"} {"name":"citroen_c4", "value":"23"} {"name":"citroen_c3", "value":"12"} {"name":"golf4", "value":"16"} {"name":"golf3", ...
1
vote
3answers
139 views

grep for strings that were found in a previous statement

I'm trying to find out if an address definition is used inside of fortigate configuration file. I extracted the section out of the configuration file, that contains the addresses. In that section the ...
1
vote
1answer
3k views

Reading grep patterns from a file

I have a couple of big text files and in the file UNIQS.txt I have a list of strings to grep from another file. The code I use is grep -f UNIQS.txt EEP_VSL.uniqs.sam > UNIQ_templates.sam which ...
1
vote
2answers
174 views

Is grep part of coreutils? (If not, why?)

I have read in a few websites that grep comes with coreutils (e.g. https://wiki.archlinux.org/index.php/Core_Utilities) However, after building them, I noticed that grep is missing. I wonder if I ...
5
votes
3answers
3k views

How can I grep for this or that (2 things) in a file?

I have a file that has "then"'s and "there"'s. I can $ grep "then " x.x x and then some x and then some x and then some x and then some and I can $ grep "there " x.x If there is no blob none ...
5
votes
3answers
3k views

How to grep for text in a file and display the paragraph that has the text?

Below is the text in the file: Pseudo name=Apple Code=42B state=fault Pseudo name=Prance Code=43B state=good I need to grep for "42B" and get the output from the above text like: Pseudo ...
4
votes
1answer
94 views

grep --include acts like --exclude

I'm trying to make use of the --include option of grep, but it doesn't behave as I expect. Consider this simplified test: Setup me@de31:~/tmp$ cat file.h This is a .h file me@de31:~/tmp$ cat file.c ...
2
votes
2answers
2k views

How can I filter those “Permission denied” from find output? [duplicate]

I started using sed recently. One handy way I use it is to ignore unimportant lines of a log file: tail -f example.com-access.log | sed '/127.0.0.1/d;/ELB-/d;/408 0 "-" "-"/d;' But when I try to ...
1
vote
3answers
731 views

When grepping a file, grep is returning true instead of the lines, why?

I am running a grep on a file that is about 13G in size. It is returning Binary file file.xml matches I was not expecting this, I thought it would return each line with my string so that I could ...
0
votes
1answer
59 views

Is there a grep switch that reads a file for filter terms?

Assuming file a.txt has: 1a 2b 3c 4d so grep "1" a.txt would return: 1a and grep "3" a.txt would return: 3c what if i want to put a criteria file named crit.txt with the following ...
10
votes
2answers
354 views

What is the difference between “*.pl” and *.pl in grep? Why does quoting change the result?

What is the difference between: grep "string" . -r --include *.pl and grep "string" . -r --include "*.pl" The latter includes files in subdirectoried while the former not. Why?
1
vote
2answers
76 views

Grep and regex, Why does the following return only a specific portion?

Why in the following: echo this is a line. | grep -o -E "[a-z]+\." The result is line. and not this is a line.? There is no word boundary or any other restriction on the regex.
0
votes
1answer
50 views

Is -r mandatory for grep?

In a directory I have a file that contains the word string. When I do: grep "string" . no results are returned. But when I do grep -r "string" . the file is returned. Why is -r option needed? It does ...
1
vote
3answers
9k views

How to find a space in a text. using grep?

How to grep one space in text ? cat a.txt| grep ' ' or cat a.txt| grep '\s '
2
votes
1answer
936 views

Issue with real-time log inspecting piping tail, grep and cut

I have to inspect a growing log in real time, and I found an issue that makes me miss some lines (I can't understand exactly what lines) using tail -f or tailf, grep and cut. I use grep because I ...
2
votes
2answers
481 views

Add a suffix string to end of each line? [duplicate]

I have two files: file01: line1 line2 line3 file02: A B C And I want to get line1 A line2 B line3 C I could possibly write a Perl script but it is better if I don't need to. I have tried ...
0
votes
4answers
162 views

Use grep with or [duplicate]

How do I search in a textfile with grep for the occurrence of a word or another word? I want to filter the apache log file for all lines including "bot" or "spider" cat ...
3
votes
5answers
397 views

How to get the lines that contain -R with grep

How can I find "-R" in files with grep? I tried grep "-R" *.GNU to get the lines that contain -R, but it returns nothing.
0
votes
4answers
5k views

Extract substring using regular expression on a Unix file

I have file with below contents . /ABC/RTE/AD_900_VOP_123/OPP /ABC/RTE/TRE/AD_900_VOP_145/BBB /ABC/RTE/AN_900_VFP_124/FBF /ABC/RTE/HD_900_FOP_153/WEW /ABD/RDV/AD_900_VOP_123/OPP ...
12
votes
2answers
607 views

“Ungrep” - which patterns aren't matched

I'm looking for a command or script to do the following - given: file1.txt: abcd efgh ijkl mnop file2.txt: 123abcd123 123efgh123 123mnop123 I want a command that does something like this: ...
7
votes
3answers
5k views

how to count total number of words in a file?

I am looking for a command to count number of all words in a file. For instance if a file is like this, today is a good day then it should print 5, since there are 5 words there.
3
votes
2answers
817 views

Get 'less' to display filename

Something that seemed quite useful to me when looking for a certain var in a bunch of config files: less * | grep some_var So this returns the value of some_var without manually looking through all ...
1
vote
2answers
92 views

Grep and sort several unsorted things in several lines (in one document)

I have a file with several unsorted things in one line which I want to put into a new file This is an example of part of the file I have: X1314448: SaMi|SM_g2554.t1 SaMi|SM_g5072.t1 Des|Des_g3808.t1 ...
5
votes
1answer
136 views

What is the meaning of this test expression []? [duplicate]

I've seen someone use command: ps -ef | grep [h]ttpd and Output is: apache 25125 31006 0 21:54 ? 00:00:00 /usr/sbin/httpd apache 26869 31006 0 22:04 ? 00:00:00 ...
-1
votes
1answer
59 views

How to get all Users and echo if they work or not?

How do I get a list of users(given from the command line) with grep and output if they are logged/work or not ?
2
votes
1answer
6k views

Read log file between two dates

I have to read log file between and my question is how to get only the text in the file wich is between two dates using unix commands? Every line contain date and I want to get the text in the file ...
0
votes
1answer
226 views

How to Get FreeBSD Grep to recognize '-' option?

I am using FreeBSD grep, version 2.5.1, and want to be able to have grep read the pattern from stdin. Other versions of grep I have used allow for the specification of - to enable this feature. ...
3
votes
3answers
132 views

| Grep, Find which file the strings came from

I have a set of PDFs, and I am running strings * | grep message This returns the strings containing that method, is there anyway I can get grep to tell me which file it is from?
2
votes
2answers
463 views

Search class names in jars

I'm using this command to search *.jar files for java classes, and I only get the name of the jars that contain those classes: grep -ral --include=*.jar SignonEJB . How can I also get the class ...
2
votes
2answers
767 views

How to find files with a certain subpath?

I need to find all xml-files that are placed in folders named config. Also config must be somewhere under a folder named trunk. For example, I am interested in all files like below: ...
0
votes
1answer
5k views

How do I redirect output from the find command (that uses grep) to a log file?

Consider the code to search for all files containing the pattern "search string": bash-3.2$ # The below find works fine.. bash-3.2$ find . -type f -exec grep -il "search string" {} \; bash-3.2$ # But ...
4
votes
1answer
1k views

How can I keep color codes with grep input?

It I grep something twice: ... | grep foo | grep bar It seems foo is not highlighted. Infact, it seems grep removes colorcodes from its input; Any way to prevent this?
0
votes
1answer
122 views

How to ask for specific parameters with grep?

I need to look in /usr/share/dict/words for a 5-letter word that starts with d or D, followed by a lowercase vowel, and ends with s. I have tried everything but to no avail.
1
vote
2answers
192 views

Split using sed

I have to split [X] ||| you owns the [X,1] ||| you own the [X,1] ||| 1 0.02020 0.07847 0.36788 3 -0.00000 -0.00000 at the pipes and output those line whose 2nd and 3rd argument are different.
3
votes
1answer
245 views

Understanding grep --label=

I am looking for an explanation how grep --label=LABEL works: Maybe somebody can give me an example [or two] on what --label= is for. I understand what grep and zgrep are supposed to do – the ...