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

learn more… | top users | synonyms

1
vote
1answer
25 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' ...
5
votes
3answers
198 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 ...
4
votes
6answers
861 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 ...
6
votes
4answers
266 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 ...
2
votes
1answer
103 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
67 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 ...
4
votes
2answers
115 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 ...
-1
votes
2answers
32 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 ...
3
votes
2answers
77 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 ...
2
votes
3answers
86 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 ...
2
votes
1answer
669 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
86 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
4answers
209 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
69 views

Help with Grep , uniq and sort

can anybody help me understand this expression grep -oP "TYPE=\w+" | sort | uniq -c
1
vote
1answer
39 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 ...
2
votes
1answer
206 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
518 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
3answers
238 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 ...
0
votes
2answers
68 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 ...
1
vote
1answer
131 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 ...
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
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
3answers
219 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
135 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 ...
1
vote
1answer
59 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
779 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
201 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] ...
4
votes
2answers
184 views

Print repeating pattern

I have a marathon file from which I want to print the names of the runners, who have made multiple runs. Something like: M, 2:08:58.0, John Lukas, USA, 1997-07-25, Paris, France F, 2:15:04:0, Abebbe ...
1
vote
2answers
71 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) ...
1
vote
1answer
78 views

How to find strings using regular expressions in grep

So I have a file list with list of the people in a company. Each line contains Position(a short string), years, name(first and last), salary and nationality(three capital letters). They are divided ...
4
votes
2answers
232 views

grep for repeated values from pattern list

I have file A.txt which is a lists of unique ids (column 1) and its corresponding values(column 2): A.txt ABC1D_T1_B1 123.4 ABC2D_T1_B2 146.7 ABC3D_T1_B1 567.8 ABC4D_T0_B2 96.8 ABC1D_T0_B1 ...
4
votes
7answers
600 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 ...
0
votes
1answer
61 views

combining grep ignore and matches

I would like to grep a file to find all instances of the text fn1 that don't have the word call in front of it and print out four lines before and after the matches (even if the surrounding lines have ...
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 ...
0
votes
1answer
372 views

grep for specific process in ps but not the grep command itself [duplicate]

If I want to check if something is running, I do ps aux | grep flamethrower, expecting just to show the processes containing flamethrower in the name. This will always find at least one process, as ...
0
votes
2answers
89 views

problem with grep -f list of pattern

After searching, reading and trying possible solutions for much about grep lines with the list of patterns, hence I am writing. It is I know a very basic and have been attended in many forums. But I ...
2
votes
1answer
61 views

Get commands a user can run from /etc/sudoers?

I need a shell (ksh) script that can be executed locally on a box that will return a list of users who have sudo access to a server and what commands they can run. For example I want to know that ...
1
vote
2answers
44 views

How to limit the number of search results per directory

How to limit the number of search results per folder, for example: With this command: grep --include=*.php -Ril '<?' '/var/www/' I get the following: /var/www/test.php /var/www/test1.php ...
0
votes
2answers
269 views

list of selectable units for journalctl

In a CentOS 7 server, I want to get the list of selectable units for which journalctl can produce logs. How can I change the following code to accomplish this? journalctl --output=json-pretty | ...
3
votes
1answer
157 views

grep fixed string at end of line

I need to grep for string containing special characters and make sure it is at the end of the line For example, in list: abc defg[h]ij I want to grep for defg[h]ij$ xyz 123*456 I want to grep for ...
0
votes
1answer
54 views

Issue finding lines using grep in UNIX [closed]

I am trying to use a .txt file with around 5000 patterns (spaced with a line) to search through another file of 18000 lines for any matches. So far I've tried every form of grep and awk I can find on ...
1
vote
3answers
51 views

How to pick out files in a folder in which the header contains specific text?

Use case: Let's say there is a folder full of large RDF+XML files and they follow different namespaces. We want to find those files that follow a given namespace (for example ...
1
vote
5answers
86 views

grep words around a token

I have some lines in a file like: This is one word1:word2 of the lines This is another word3:word4 of the lines Line without a match Yet another line word5:word6 for test I need to grep ...
0
votes
1answer
60 views

No output from grep -P 'com\K\w+'

I have a source file saved off the internet which has various links I want to pull data from. For example https://blahblah.com/uniquetext I'm using grep -oP 'com\K\w+' source.txt > list.txt ...
1
vote
2answers
896 views

grep pattern exacly matching from file and search only in first column

I have a bigfile like this: denovo1 xxx yyyy oggugu ddddd denovo11 ggg hhhh bbbb gggg denovo22 hhhh yyyy kkkk iiii denovo2 yyyyy rrrr fffff jjjj denovo33 hhh yyy eeeee fffff then my pattern file ...
1
vote
2answers
733 views

How to grep for something that's in an environment variable and has a forward slash?

I want to grep a file, and I want to get all the lines that have a certain environment variable (to be exact, $PWD). Of course, using just cat file | grep '/'$PWD'/' is not working, since $PWD ...
0
votes
2answers
70 views

Read file and find all occurances and generate hash for the content in between the occurance

I have a file like this : 1 Record|1111|ABC 2 text in between for record 1 3 text in between for record 1 4 Record|2222|XYZ 5 text in between for record 2 6 Record|3333|XYZ 7 text ...
6
votes
2answers
878 views

Suppress 'file truncated' messages when using tail

I'm tailing a log file using tail -f messages.log and this is part of the output: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce eget tellus sit amet odio porttitor rhoncus. Donec ...
2
votes
1answer
79 views

How do I grep for multiple patterns on multiple lines?

To be precise Some text begin Some text goes here. end Some more text and I want to extract entire block that starts from "begin" till "end" with awk we can do like awk '/begin/,/end/' text ...
1
vote
2answers
21 views

Zero input_file_names in Grep

From the manual for grep, the general form of grep usage is: grep options pattern input_file_names In particular, it is stated "There can be zero or more input file names." What files are ...