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

learn more… | top users | synonyms

0
votes
0answers
9 views

Interpreting regex wildcards with grep

This is a really simple question, but even after reading about wildcards/regex, I can't seem to grasp entirely what the differences between these commands are: grep . test.txt this one will look ...
3
votes
2answers
152 views

How costly is case insensitive search as compared to case sensitive search?

I dont think grep -i is exponentially (wrt to the number of characters to be grepped) more costly (time wise) than a normal grep because the run times are not too different. But theoretically it ...
1
vote
1answer
33 views

How to filter a basic csv by columns

How do I filter by third column of the following file list.txt [[ list of people ]] billy baxter - @baxter - b.baxter@woods.com james woods - @woods - j.woods@someother.com I currently have cat ...
0
votes
1answer
37 views

grep to compare files not working

I successfully used: grep -wFf inputqueries.txt seachedfile.txt > results.txt to search searchedfile.txt for each query in inputqueries.txt. inputqueries.txt looks like: 213.183.56.186 ...
-1
votes
0answers
34 views

How to merge these three task in a single command ( grep | sed | echo)

I am trying something where I parse out from the tags in a file then add back the HTML. I see everyone suggest not to do such with regEx (grep). but here it is grep -m 1 -oP ...
27
votes
5answers
75k views

Count total number of occurrences using grep

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
1answer
52 views

What does this grep expression mean? [on hold]

\*.\?[A-Z]\?.* This grep command is cryptic. I understand that it is supposed to search for uppercase commands.
5
votes
5answers
111 views

Run `grep` excluding a file in a specific path

I want to exclude the file ./test/main.cpp from my search. Here's what I'm seeing: $ grep -r pattern --exclude=./test/main.cpp ./test/main.cpp:pattern ./lib/main.cpp:pattern ./src/main.cpp:pattern ...
1
vote
1answer
28 views

Get `grep` to not output file name

When I use grep -o to search in multiple files, it outputs each result prefixed with the file name. How can I prevent this prefix? I want the results without the file names.
22
votes
6answers
9k 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 ...
5
votes
2answers
85 views

How to search for text in a file ignoring newlines?

I'd like to search for text that may be split over several lines in a file. A grep that would ignore line breaks and return the matching span of lines. e.g. I would be searching for is an example ...
3
votes
3answers
229 views

Extracting unique piece of text from file with awk, sed or grep

From the output of pactl list sink-inputs, I need to grab the sink input number for VLC. Before that, I'm trying to extract the piece that contains the output for only VLC. All the methods that I ...
1
vote
2answers
31 views

Extract some columns from grep output

I've run the command grep -a --binary-file=text "DLDM" /home/path/ldm.log-$1* | grep -a "$line" and the output is something like this :- /home/path/ldm.log2015:"unix","20150518 ...
30
votes
8answers
6k views

Is there a way to modify a file in-place?

I have a fairly large file (35Gb), and I would like to filter this file in situ (i.e. I don't have enough disk space for another file), specifically I want to grep and ignore some patterns — is there ...
13
votes
3answers
18k 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 ...
-1
votes
0answers
29 views

Skip Duplicate Output [duplicate]

I using this command to print an output :- grep -a --binary-file=text "RRRR" /home/path/file.log-$1* | awk -F, "/$line/ {print \$2 \",\" \$9 \",\" \$10 \",\" \$11 \",\" \"(\" \$23 \")\"}" example ...
1
vote
1answer
50 views

what is meant by “^$1” in shell script?

#!/bin/sh #emp3.sh: using if and else # if grep "^$1" /etc/passwd 2>dev/null then echo "pattern found - job over" else echo "pattern not found" fi in the above programme what is "^$1" and ...
0
votes
1answer
36 views

grep searching groups

I'm trying to learn to use grep groups, like sed \1\2\3, but have a problem. For example I filtering /etc/services file to separate all ports. What I do: ~$ grep -E '[0-9]{1,5}/(tcp|udp)' ...
4
votes
1answer
77 views

What is the opposite of “grep”?

Say I'm printing out a long series of strings, and instead of only showing lines containing a certain pattern (which one uses "grep" to do), how do I filter out certain patterns?
1
vote
2answers
60 views

How to perform grep on 'man unix_command'?

Often while going through the output of man man awk I Need to perform grep, for e.g. in man awk, I need to find the definition of a particular flag, variable etc. Can anyone tell me, what would be ...
1
vote
5answers
62 views

Grep 2 different requirements in one command line statement

How would I print the last 3 lines that have the string #include from tester.c and if fewer than 3 lines contain the string, print the entire file. So far I have: grep "#include" tester.c | tail -3 ...
2
votes
2answers
42 views

Can't get GNU grep 2.12 to handle LF character in regex expression

I've been at it for over an hour, but can't find why it's not working. I'm searching an HTML document for "\nSome text". Simple enough. But he following commands won't work: grep -Po ...
-1
votes
1answer
24 views

Grepping entire system but dodging process files and the like [duplicate]

I have so many systems I need to do and I find it really impractical for me to grep everything/folders individually.
1
vote
0answers
49 views

Grepping multiple instances of a string, with context, from a file

I have a MySQL dump file, which is mostly INSERT statements. I want to grep out instances of the string 'media' from a field in a particular table, with +/- ~10 characters of context. The string might ...
1
vote
1answer
34 views

Conditional awk across 4 columns

I have a tab-delimited file with 9 columns as follows: 1 25555818 T 14 0 0 0 14 0:0:0:14 2 25555819 T 14 7 0 0 7 7:0:0:7 3 25555820 G 13 0 0 13 0 ...
1
vote
4answers
214 views

Wildcards for filepaths aren't working in grep [duplicate]

I need to grep words like these: ABC-DEF AB2-DEF AB3-DEF AB-DEF So I was trying: grep AB*-DEF grep -w -AB*-DEF grep -w AB*DEF But neither of them are working. Please help.
6
votes
6answers
12k views

make grep output without trailing newline

Please consider this snippet: X=$(grep -m1 'some-pattern' some-file | sed -n 's/.* //p') I want to put last word in a variable if some pattern condition is matched for lines in arbitrary text file ...
-3
votes
1answer
44 views

grep-ing - I think [closed]

I have a multitude of files (2TB) which all have word data in them. All the data follows the same format but the information slightly changes I need to be able to pull out specific data from the files ...
2
votes
2answers
87 views

Extract substrings from each line. These substrings are in comma separated, “name=value” format

I have lines in a file that are comma separated. There are no column headers, it's mostly comma separated 'name=value' pairs. Here is some test data: ...
10
votes
5answers
7k views

How do I recursively grep through compressed archives?

I'm trying to find out what modules use Test::Version in cpan. So I've used minicpan to mirror it. My problem is that I need to iterate through the archives that are downloaded, and grep the files ...
1
vote
2answers
32 views

Using Unix, when detecting a pattern, we need to detect its corresponding other pattern

When detecting the line containing the pattern night, we need to detect its corresponding line containing the other pattern === which is just occurring at a higher line as shown below. File content: ...
7
votes
3answers
138 views

How to use [\w]+ in regular expression in sed?

I am on Windows, but I guess my question is still rightly placed here. C:\Users\User>grep --version GNU grep 2.6.3 C:\Users\User>sed --version GNU sed version 4.2.1 I noticed that the ...
2
votes
3answers
48 views

Search a String in a directory- Get output without filename

I am executing the below command to display the lines which matches the pattern. find ./files/ -name "*.txt" -print0 | xargs -0 grep "5|20150507" And output is ...
6
votes
2answers
677 views

bash - why does \x0d\x20 erase the line

This is the view from gedit editor: and the view from vim editor: I then try to grep it, it did grep successfully if i put Log instead of Tog, but the output is corrupted: [xiaobai@xiaobai grep]$ ...
3
votes
4answers
46 views

Find the last occurence of a string in a given filetype in all subdirectories

I have multiple sub-directories each with different depths. I need to search for the last occurrence of a string in a specific filetype (say *.out). How can I accomplish this? I have tried: grep -r ...
1
vote
0answers
16 views

tool in terminal like helm-occur/helm-swoop for terminal?

I don't know whether this is the right place to post this question, but if you are not an Emacs user, I'll explain the basic usage of helm-occur/helm-swoop. I like helm-occur/helm-swoop for Emacs ...
1
vote
2answers
54 views

Pipe to my own script

I've recently noticed this message from grep "grep: warning: GREP_OPTIONS is deprecated; please use an alias or script" I receive this warning because --color=always is defined in my .bashrc file. ...
0
votes
3answers
30 views

To grep version number from Wordpress plugin folder

What will be grep regex to extract version number like Version: 3.1.5 * Version: 3.1.5 Will output 3.1.5 But It should not catch likes MIME-Version: 1.0\n Here is my grep command grep ...
36
votes
4answers
3k views

Reverse grepping

Let's say, I have a really big text file (about 10.000.000 lines). I need to grep it from the end and save result to a file. What's the most efficient way to accomplish task?
0
votes
4answers
69 views

What the equivalent of “grep | cut” using sed or awk?

Say I had a config file /etc/emails.conf email1 = user@dinkum.dorg email2 = user@winkum.worg email3 = user@stinkum.storg and I wanted to get email2 I could do a: grep email2 /etc/emails.conf | ...
17
votes
6answers
13k views

How to pipe the result of a grep search into a new vi file

I'm using grep -e Peugeot -e PeuGeot carlist.txt to search through carlist.txt and pull out some items and I presumed that grep -e Peugeot -e PeuGeot carlist.txt | vi would pipe it through for me but ...
2
votes
1answer
48 views

Execute commands from history that match regex or grep

I was wondering if its possible to execute commands from history that match a certain regex? I know you can do something like fc 232 248 And it will go into your history and then do revisions ...
0
votes
1answer
23 views

Filtering Log Output on Separate Lines

I did a recursive grep in a directory to find all files that would match as follows grep -ER "match_string1|match_string2" /path/to/dir/ What I get as output is: ...
0
votes
2answers
30 views

grep to ignore special characters in a file [closed]

I have a java file and I want to list the number of times the word port occurs. But the only problem is I have many functions which have the work port in it too. Here is an example of a function : ...
6
votes
6answers
2k views

How do I grep recursively through .gz files?

I am using a script to regularly download my gmail messages that compresses the raw .eml into .gz files. The script creates a folder for each day, and then compresses every message into its own file. ...
4
votes
1answer
3k views

Is GREP_OPTIONS= --color=always ignored?

I was playing around with setting GREP_OPTIONS and couldn't get it to work. Just curious as to why. Simple test commands output: richard@ubuntu:~$ echo $GREP_OPTIONS richard@ubuntu:~$ ...
-2
votes
1answer
297 views

How to use Cut and Grep command to find data separated by “:” [duplicate]

In my simple database, it contains text of like, example, soldiers. Name:Rank:Gender:Age:Years of Service Tom Corporal:Recruit:Male:19:2 Nicole Sergeant:Corporal:Female:30:10 Daniel ...
0
votes
1answer
1k views

How to execute grep in tcl for getting XYZ-123 type pattern

How can I execute this grep command in TCL? grep '[A-Z][A-Z][A-Z]\-[0-9][0-9][0-9]' file1 > file2
0
votes
2answers
45 views

find and list -R returning different number of files

I'm trying to create an array variable with a list of files to use in a small script, needing the full path to the file. Looking around I tried something like this: find /path/ -t f | grep ...
1
vote
2answers
48 views

awk/grep to match word in two files [duplicate]

I have two files: file1: 905894 1197693 3703749 file2: 905894 Test1 1197693 Test2 3703749 Test3 I want to get the values in the second column if elements in file 1 column 1 matches any of ...