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

learn more… | top users | synonyms

2
votes
2answers
116 views

How to return 0 if a pattern is matched from a file? [duplicate]

I have a binary that repacks android kernel (not mkbootimg). I'm making a script to automate the process. I don't want any output on the screen. So I have redirected the output to a file named ...
-1
votes
1answer
85 views

grep and print all pattern in one lane

I have a file with a list of pattern like this K00001 K00003 K00005 I want to grep and print my pattern in a tab delimited table (the original table is without blank line) like this: K00001 ...
3
votes
4answers
129 views

fgrep beginning of line?

I'd like to use fgrep to handle searching literal words with periods and other meta-characters in grep, but I need to ensure the word is at the beginning of the line. For example, fgrep 'miss.' will ...
0
votes
1answer
228 views

How do I grep on a live log (stdout)?

I'm not sure if that what stdout is, but that's what I think. What I want to do is filter out a certain log message when running an executable. I tried this: Executable 2>&1 /dev/null | ...
2
votes
3answers
296 views

How can I insert the contents of a file into a string in bash

I would like to append the contents of a multi-line text file after a particular line in a string. For example, if the file file.txt contains line 1 line 2 I'd like do so something like printf ...
1
vote
1answer
620 views

How to do a netstat that will only filter based on pid

How can I have the following command below just show/filter based on the PID's I'm looking for? sudo netstat -lp --inet The results come back as this Proto Recv-Q Send-Q Local Address ...
3
votes
1answer
71 views

Show exact number of CRLF occurrences in file

grep -c $'\r\n' file returns the exact same number as grep -c $'\n' file, it shows the number of LF in the file instead of the number of CRLF. (The file definitely does not contain that number of ...
2
votes
2answers
138 views

Group matching with grep includes extra characters

I wanted to extract some text with regex in bash, so I decided to try the following simple example out. echo "abc def ghi" | grep -Po " \K(.*?) " I was expecting to get a "def", but to my surprise ...
15
votes
2answers
3k views

grep inside less?

I'm currently sifting through a lot of unfamiliar logs looking for some issues. The first file I look at is Events.log, and I get at least three pages in less which appear to display the same event ...
2
votes
1answer
153 views

counting occurrences of a string

I have a large database of this format: 0500506 gi|561108321|ref|NC_018143.2| 71446 0 0500506 gi|561108321|ref|NC_018143.2| 71447 0 0500508 gi|561108321|ref|NC_018143.2| 71449 0 0500509 ...
1
vote
1answer
95 views

Why recursive grep does not work with STDOUT? [closed]

I've been long used to have some custom aliases in my Ubuntu/Mint machines, like alias grep='grep -irn --color --line-buffered'. However, I've noticed that since a while ago this stopped working for ...
0
votes
1answer
115 views

Different usage of grep

I know grep can be use to do partial search, for example if i use echo "Enter example" read example echo "Enter Subject" read subject grep -i ^$example info.txt | grep -i ^[^,]*:$subject The ...
2
votes
5answers
2k views

grep files from list

I am trying to run grep against a list of a few hundred files: $ head -n 3 <(cat files.txt) admin.php ajax/accept.php ajax/add_note.php However, even though I am grepping for a string that I ...
1
vote
3answers
286 views

How do I make an output for grep fail?

I am using if-else statement to search for keywords and displaying the results in the terminal, here's an example of my code. read finding if ["$finding" != "" ]; then grep $finding ...
0
votes
0answers
44 views

egrep for specified strings and newline

I receive a prespecified list of strings. In a number of textfiles (example below), I want to search for strings, that do not start with one of the strings in the list. From time to time, a blank link ...
1
vote
3answers
1k views

Pattern Search between specific lines and print line numbers

I have a file of 20 lines. I want to search for a string between the lines 10 and 15 and print the string along with the line numbers of the original file. I have tried sed -n 10,15p file | grep -n ...
7
votes
5answers
2k 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, ...
0
votes
2answers
223 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
34 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 ...
-2
votes
1answer
569 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
440 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
1answer
108 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 ...
1
vote
2answers
63 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
218 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 ' ...
0
votes
1answer
44 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
51 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 ...
3
votes
3answers
261 views

extract from line to line and then save to separate file

I tried my luck with grep and sed but somehow I don't manage to get it right. I have a log file which is about 8 GB in size. I need to analyze a 15 minute time period of suspicious activity. I ...
1
vote
1answer
114 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 ...
1
vote
2answers
69 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 ...
4
votes
4answers
2k 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 ...
1
vote
1answer
56 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
327 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
2k 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
656 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
156 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
79 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
131 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
38 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
104 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
173 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
2k 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
116 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
-1
votes
4answers
1k 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
85 views

Help with Grep , uniq and sort

can anybody help me understand this expression grep -oP "TYPE=\w+" | sort | uniq -c
1
vote
1answer
59 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
461 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
1k 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
447 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
94 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
169 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 ...