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

learn more… | top users | synonyms

6
votes
5answers
926 views

grep skip n lines of file and only search after

I have a huge log file and want to grep the first occurrence of a pattern, and then find another pattern right after this occurence. For example: 123 XXY 214 ABC 182 558 ABC 856 ABC In my example, ...
8
votes
4answers
13k views

How can I find all files that do NOT contain a text string?

What concise command can I use to find all files that do NOT contain a text string? I tried this (using -v to invert grep's parameters) with no luck: find . -exec grep -v -l shared.php {} \; ...
0
votes
2answers
210 views

Using grep for listing certain lines from a file

Using a random file, such as /usr/share/vim/vim74/tutor/tutor, is there a way to list all lines that start with a 5 letter word ? How about the lines that end with a 5 letter word ? I've been ...
2
votes
1answer
30 views

How do I make grep list the count of matches before the filename?

grep -cZ has the weird behaviour that, while filenames are nul-terminated, the count of matches appears after the corresponding filename. Via od -c: 0000000 / u s r / i n c l u ...
1
vote
1answer
79 views

How can I teach grep to treat properties-files like text-files

Since I upgraded grep from 2.16 to 2.21 it treats .properties-files like binary files. This sucks because I like to use grep -I ... to exclude binary files from the search results and ...
0
votes
1answer
303 views

How to use grep and cut together?

Lets say I'm doing a database for fruits. Using a text file for it, inside contains, in this format, (Fruit:Quantity:Cost) Apple:10:1 Orange:20:2 Pears:10:3 Banana:20:4 10 Apples at $1 each. 20 ...
1
vote
2answers
58 views

find and replace a value in a line of text

I have a text file which contain only 1 line of text 1314:Battery:1.90:50:30 I'm trying to figure out if is there anyway to do a grep and sed to change the value 50 and 30 to the following ...
3
votes
2answers
141 views

Select lines starting with specific numbers

I have to show the PID, PPID and STATUS of the procceses on the system, but only the ones which PID starts with numbers in the range 5-8. So i tried something like this... ps xao pid,ppid,s | grep ' ...
1
vote
2answers
66 views

How to make a filter more efficient

I've created a script to compare a list of users from a MSSQL database against a list of disabled AD users. The tool we use for AD authentication returns data in the following format (with plenty ...
0
votes
1answer
35 views

Why the grep result depends on folder path? [duplicate]

I meet a strange phenomenom when using grep on Solaris 10: I try to use grep to find creat related DTrace probes. When in a folder (/data1/nan), it works OK: bash-3.2# pwd /data1/nan bash-3.2# ...
0
votes
2answers
45 views

extracting lines from a large text file

I have a text file with data that looks like this (1875 lines to be exact) chr1 MOTEVOC_cage_181208 TF_binding_site_cage_181208 6585538 6585547 0.905022147 - . TF_binding_site_cage_181208 ...
1
vote
1answer
28 views

output neighbouring lines with line numbers while grepping

Is there a way to output the neighbouring lines along with the line numbers while grepping the contents of a file? I'm trying to get outputs of the form: $ ~/myscript.sh download file # 'download' ...
1
vote
1answer
90 views

grep stopped working [closed]

This is a weird question. I was using the normal grep -w command to search through millions of lines to extract specific lines that contained the word that I was interested in. grep -w Search_word ...
4
votes
4answers
593 views

grep with logic operators

Is there a grep-like utility that will enable me to do grep searches with logic operators. I want to be able to nest and combine the logical constructs freely. For example, stuff like this should be ...
2
votes
3answers
1k views

Reverse match in sed, replace opposite of what was found

Say I have this output from my syslog, precalculated src_hash => 20 bytes @ 0x7f811c001e20 A6 2D E5 CD 2A BA F0 42 56 66 19 D4 61 1A E3 A0 .-..*..BVf..a... C7 5E 5F 77 ...
4
votes
6answers
923 views

grep invading my ps [duplicate]

When I'm checking for some process, I usually write ps aux | grep myprocess And sometimes I get the output of eimantas 11998 0.0 0.0 8816 740 pts/0 S+ 07:45 0:00 grep myprocess if ...
5
votes
3answers
205 views

grep for multiple regexes, and count the number of occurences

Say, I have a file, and multiple regexes have to be searched in it and the number of matches for each regex has to be counted. Thus, I cannot combine the patterns: grep -Po ...
6
votes
4answers
297 views

How to grep netcat output

I'm trying to grep live text stream from netcat, but it doesn't work for me: netcat localhost 9090 | grep sender returns nothing, but I'm sure that it should. If I redirect the netcat output to a ...
4
votes
2answers
116 views

Error getting the string between two patterns

I want to get a string between two patterns. The pattern is the first environment <p> </p> in an html file. <p>Sorcery, R (1) </p> <p ...
2
votes
1answer
108 views

Why is the end-of-line $ anchor not working with the grep command, even though the front-of-line ^ anchor is?

Very new to UNIX but not new to programming. Using Terminal on MacBook. For the purposes of managing and searching word lists for crossword construction, I'm trying to get handy with the Grep command ...
1
vote
3answers
71 views

Grep lines that cotain “1111-11-11” or “2382-21-20”. (Any Numbers)

I have tried to do this and I came up with this grep -E '\<[0-9]{4}"-"[0-9]{2}"-"[0-9]{2}\>' It doesn't work and the reason for that is the "-" and multiple grep things, so I tried dividing ...
3
votes
4answers
462 views

Display lines inbetween text with grep

I know that I can use the -A and -B command for grep to get a lot of what I am looking for however that is not quite what I want. I am looking to parse the httpd.conf file to search for a domain. ...
3
votes
2answers
83 views

Why can't I grep this command line option?

The output of man icc contains -Ldir Tells the linker to search for libraries... Doing man icc | grep "\-L" gives back the "-Ldir" line while man icc | grep "\-Ldir" does not. What am ...
-1
votes
2answers
35 views

OSX bash. grep for string “--version=”

How can I search for string --version= using grep in OSX bash? When I try something like this: grep -rI --exclude-dir=out "--version=" . I get grep: option `--version' doesn't allow an argument ...
2
votes
3answers
93 views

Execute command within variable

I'm trying to execute a command, stored within a variable: cmd="grep -i \"word1\" filename | grep -i \"word2\"" eval $cmd But when I execute the script I get the errors: grep: |: No such file or ...
3
votes
1answer
766 views

Invalid back reference using grep

So I am trying to find 6-letter words that consist of one character repeated three times followed by another character repeated three times. For example aaabbb or oookkk. I am trying: grep -E ...
-2
votes
3answers
88 views

How to list filenames within a folder based on a pattern supplied?

I'm trying to find a command that will list all files in a folder containing a keyword that is inputted. I've tried grep -l but it will not list anything
2
votes
0answers
386 views

exit code of grep in trap where the script is launched by upstart service

Recently I encountered a problem in ubuntu upstart and trap in Bash shell. I use ubuntu 12.04. The upstart script(/etc/init/player.conf) is: start on (local-filesystems and runlevel [2345]) stop on ...
3
votes
4answers
4k views

How to detect dos format files in git bash

Git Bash is a nice bash shell you get in Windows as part of the installation of Git. It comes with other typical unix tools bundled inside, such as grep, sed, awk, perl. It doesn't have the file ...
0
votes
2answers
530 views

Removing a long string from php files - using grep and sed?

I have encountered some malware on my Linux server, and am trying to remove it from many php files. I've tried endlessly with grep | sed and grep | tr and couldn't even erase a simple text string, ...
-2
votes
4answers
263 views

How to ignore the lines starts with # using grep / awk

cat /etc/oratab #test1:/opt/oracle/app/oracle/product/11.2.0.4:N +ASM2:/grid/oracle/app/oracle/product/11.2.0.4:N # line added by Agent test2:/opt/oracle/app/oracle/product/11.2.0.4:N ...
-1
votes
1answer
70 views

Help with Grep , uniq and sort

can anybody help me understand this expression grep -oP "TYPE=\w+" | sort | uniq -c
1
vote
1answer
40 views

In which directory is node running?

In trying to figure out how some application that listens on port 8088 is running, I see that it has PID 15020: $ netstat -ntulp Proto Recv-Q Send-Q Local Address Foreign Address ...
9
votes
4answers
13k 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.
2
votes
1answer
237 views

How to count occurrences of all the words in all the files of a directory using grep? But with count incremented only once per word per file

I have already asked a similar question but people misunderstood what i was asking. I was asking how to generate a list of every word with a word count incremented only once per word per file. For ...
0
votes
2answers
605 views

How can I store each seperate entire line in a text file into an array?

I have a file called "threewords". It contains the information: \#gray speedy bee gr-A | sp-E-d-E | b-E \#gray greedy pea gr-A | gr-E-d-E | p-E When I run the command: cat threewords | grep ^# ...
0
votes
2answers
70 views

Command to see if a word is in a list of files and output how many files it is in

There is a similar question to mine already but mine has a slight difference. I want to see how many files contain each word. When a file has a word then it increments the counter and then continues ...
0
votes
3answers
258 views

kill several processes using awk tools

I want to stop several processes using awk.My command is like this: sudo ps -ef|grep wget |grep -v grep|awk '{print $2;sudo kill -STOP $2}' I want to stop all processes which is running wget. $2 of ...
6
votes
2answers
10k views

Grep 'OR' regex problem

I am trying to use grep with a regex to find lines in a file that match 1 of 2 possible strings. Here is my grep: $ grep "^ID.*(ETS|FBS)" my_file.txt The above grep returns no results. However if I ...
1
vote
1answer
137 views

Counting the instances of specific words in a text, using awk [duplicate]

If I have a file words_of_interest.txt with one word per line, is there a way to use awk (or some other *nix tools) to obtain the number of times each of these words occurs in another text file ...
1
vote
2answers
27 views

Erasing in stdin all instances of regexes defined in a file

I am after something like a combination of sed 's/pattern//g' and grep -f patternfile.txt. Basically I would like the input stream to be stripped of all instances of the regex patterns defined in ...
1
vote
2answers
72 views

Extracting list of patterns which are output of another command

I can extract list of patterns using following command, fgrep -A 1 -f patternlist.txt filename.fasta but, is there a way I can extract without creating another file (patternlist.txt in this case) ...
2
votes
1answer
41 views

comparing 2 lists with additional data to be printed

I have a file lets say file1.txt ENSG00000223116 AL157931.1 ENSG00000233440 HMGA1P6 ENSG00000207157 RNY3P4 ENSG00000229483 LINC00362 ENSG00000252952 RNU6-58P I have another file say ...
1
vote
3answers
231 views

Replace a string and replace it with a part of itself

I am cleaning up my data that is stored in text files. Each line starts with a category label followed by the actual data that I want to clean up. There are many text files in different subfolders, so ...
1
vote
5answers
144 views

How to get the unique count of a particular part of a string

I have a set of data in a file. psf7433-nlhrms unit7433-nobody unit7333-opera bpx7333-operations app7333-osm unit7330-partners psf7331-pdesmond unit7333-projm mnp7330-redirect unit7333-retailbanking ...
4
votes
7answers
641 views

Grep for a line containing only 5 or 6 numbers

How would you grep for a line containing only 5 or 6 numbers? Something like this. case 1 (has leading space) 10 2 12 1 13 case 2 (no leading space) 1 ...
2
votes
2answers
1k views

How to grep for same string but multiple files at the same time?

I have a set of log files that I need to review and I would like to search specific strings on the same files at once Is this possible? Currently I am using grep -E ...
1
vote
1answer
62 views

vim :grep using the bash 'globstar' option

I am (slowly) switching to Vim for everyday Ruby on Rails coding (Linux Cinnamon 64bit). Being a newbie, I recently came across something I don't understand. I want to use the :vimgrep and :grep ...
2
votes
3answers
977 views

grep only matching word

I have a temp file, and I want to grep the only word that matches the pattern instead of whole word. i tried grep -o <pattern> file but its not giving me desired output Input xi29 vddf vss ...
1
vote
2answers
218 views

Filter Large Data Sets on Dates with Command Line

I have a huge data sets that consists of tab separated values that are stored in rows. An example row looks like this: Dec 4 14:37:36.381651 algorc1 [27751:l@27932]/error: [] - [T0000A124M5] ...