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

learn more… | top users | synonyms

1
vote
2answers
274 views

How to count the number of words and print the lines that match exactly a given pattern?

I want to count the number of words and print the matched pattern lines which matches exactly with following pattern: abc-ERROR: The input File contains: # abc-ERROR: xyxxkkfgfr # def-Error: ...
4
votes
3answers
980 views

Uniquely identifying java processes with same name

I have two java processes which run using the same file name, MyApp.jar (for example). /usr/java/latest/bin/java -jar MyApp.jar These jars exist in different places and use different ...
0
votes
1answer
91 views

(e)grep and atomic grouping [comprehension question]

I am trying to understand the correct use of »atomic grouping« a.k.a. »independent subexpressions« a.k.a. »non-backtracking subpattern« [this are the terms I found ...
4
votes
2answers
2k views

greedy and lazy regular expressions (comprehension question)

I am teaching myself regular expressions, and I got stuck at »greedy« vs. »lazy« repeatings. What I found out so far is that »greedy« means that the RegExp ...
2
votes
1answer
94 views

How can I get grep to work with “->” as the pattern?

I have this text in a file called temp: -rw-r--r-- 1 root root 15776 Oct 15 2010 dnd-copy -rw-r--r-- 1 root root 15776 Oct 15 2010 dnd-link -rw-r--r-- 1 root root 15776 Oct 15 2010 dnd-move ...
2
votes
2answers
290 views

add “#” in begining to selected lines in File

Requirement : ADD someting (i.e #) in begining of every line in file A which is grep from file B File A abcd abdc sdfg asdfa jon ram File B jon abcd grep file B from file A and add "#" ...
1
vote
2answers
296 views

Confused about inverse grep

So, when you use inverse in grep (egrep -v), this literally means the output is shown upside down (flipped over)? I think I was more confused when I saw the following examples $ egrep -v '\ ' ...
1
vote
1answer
1k views

Confused about word boundary

I have been researching this a lot, but I am still not clear on it. What does word boundary mean? What does it do? So, for example, could someone explain this command to me please? egrep ...
5
votes
3answers
2k views

Output to stdout and at the same time grep into a file

I have a script that outputs text to stdout. I want to see all this output in my terminal, and at the same time I want to filter some lines and save them in a file. Example: $ myscript Line A Line B ...
1
vote
1answer
697 views

What is a sure fire way to find all files and/or path that contains 2 keywords?

I was doing a find . -iname '*sitesearch*' | grep demo because I know the file should be some/path/SiteSearch/demo/SiteSearch.html, but it turned out a person put the file in as ...
0
votes
3answers
2k views

Regular Expression for finding double characters in Bash

I am looking for a regular expression that finds all occurences of double characters in a text, a listing, etc. on the command line (Bash). Main Question: Is there a simple way to look for sequences ...
1
vote
2answers
2k views

Regular expression problem(s) in Bash: [^negate] doesn't seem to work

When I execute ls /directory | grep '[^term]' in Bash I get a regular listing, as if the grep command is ignored somehow. I tried the same thing with egrep, I tried to use it with double and single ...
0
votes
3answers
105 views

Grep end regex matching

On OS X, system_profiler SPHardwareDataType outputs: Hardware Overview: Model Name: MacBook Pro Total Number of Cores: 4 L2 Cache (per Core): 256 KB L3 Cache: 8 MB Memory: 8 GB I want to ...
12
votes
1answer
4k views

Why doesn't grep ignore binary files by default?

The manpage for grep describes the -I flag as follows: -I Ignore binary files. This option is equivalent to --binary-file=without-match option. It also says this about binary files: ...
1
vote
2answers
309 views

Difference betwen grep pattern ^$ and ^

I understand that grep matches all the blank lines for the pattern ^$. But what does just ^ means. When I gave grep '^' filename. It matched all the lines. Also grep '' filename matched all the lines ...
1
vote
1answer
973 views

How to properly use /usr/xpg4/bin/grep -F

I have a problem producing filtering out hanzoMollusc (2)from my grep. https://node.hanzo.com/production/application/ (1) https://node.hanzoMollusc.com/Messaging/Receiver (2) My grep command is ...
0
votes
1answer
459 views

ps | grep shows bad output in subshell with jobs running in the background

I am using bash. I have a file named "a2draw" that contains only 1 line: sleep 99999 I start it using this command: bash a2draw & Now, I know and understand the trick with square bracket ...
4
votes
4answers
272 views

Grep of many keywords over many files: speeding it up

I am currently facing a "performance problem" while using grep. I am trying to locate the occurrences of many (10,000+) keywords in many (think Linux kernel repository size) files. The objective is to ...
3
votes
1answer
2k 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:~$ ...
0
votes
1answer
743 views

Using grep with symbolic link

I don't know how to ask this, but let me explain. I have a text file (named bla) in my ~/user/Dropbox folder. I would like to grep on it from any folder in terminal. For example, I'd like just type ...
0
votes
3answers
101 views

regex suggestion

echo "223255/12345678 " | grep '[0-9a-zA-Z/\-\?:\(\)\.,"\+]{1,34}' According to the regex, it can have any of 0-9 a-z A-Z / - ? : ( ) . , " + of upto 34 chars in any order. Am I ...
4
votes
4answers
138 views

Bash-completion and grep

I installed a program (iftop) on Debian Squeeze but some days ago I forgot it's name. I had only this information about the program: 1) It was called *top 2) I could find it using bash-completions. ...
2
votes
3answers
303 views

awk, sed, grep, perl… which to print out in this case?

I have this syntax in a file (http response times from analog): <thead><tr><th class="x">seconds</th><th class="R">reqs</th><th ...
1
vote
3answers
566 views

Newbie struggles with grep, sed, awk to filter html

I am a beginner linux user, trying to teach myself how to use linux tools on a cygwin install. I decided to make up a project to try to teach myself the basics of shell scripting and simultaneously ...
5
votes
5answers
7k views

Use grep to find all files in a directory with two strings [duplicate]

I am trying to figure out the correct syntax to find two strings, the entire part of each string, anywhere (doesn't have to be near each other) in a file. So any file that has both foo and say the ...
3
votes
4answers
111 views

grep to find “print” not “#print”

In debugging, I use a lot of 'print' and commenting out it with '#print'. How can I use grep to find the line without '#' before 'print'? # print <- not detect #print <- not detect abc # print ...
2
votes
1answer
195 views

Grepping number in a file

I have this command $ cut -f2,3 AIS2F1 | grep [2-9][0-9]* | cut -f1 So my second and third fields are something like this Ben 434 Me 12 you 56 So, I thought that the logic should be to cut ...
4
votes
4answers
643 views

Count lines matching pattern and matching previous line

I want to count the number of times that a role is successfully deleted. The problem is that one line of the log file will show that the script is about to delete the role: Prepare to remove role X ...
-2
votes
1answer
287 views

Search low values in mainframe files

I am working with mainframe files and it seems that the low values (x'00') exists in the records in the file which throws off my import for fixed block. Does anyone know how to eliminate those ...
0
votes
3answers
9k views

How to tell grep to match special character at beginning of each word [duplicate]

I have certain questions regarding grep. Why does the following command match '<Hello'? $ grep -E "\<H" test Hello World <Hello H<ello What needs to be done to match '<Hello' only? ...
2
votes
2answers
450 views

find all cpp files and list only those files with names that match a pattern (regex) does not work

I have a whole repository of files and I am trying to get a list of files that match a certain criteria. For example, let us say that I want to take all the files that have the string foo1 and ...
6
votes
1answer
2k views

grep: Ignoring GREP_OPTIONS to search case-sensitive

I have set GREP_OPTIONS="--ignore-case --color" in ~/.bashrc as I normally want grep to work case-insensitive. However, there are times when I need grep to actually search case-sensitive, but the man ...
2
votes
2answers
822 views

Use of quotes in GNU grep regular expressions

I could see that certain patterns in the GNU Grep can be enclosed within brackets and certain others need not be. For example, matching the beginning of a word works only if it is enclosed within ...
1
vote
2answers
298 views

Fast utility that indexes files/directories on centos 6 for faster searching through the filesystem

I need to often search a large directory structure (with 1 G / 13K files of data). find / grep take a lot of time. Is there any utility (or can one make an index of these files) for faster searching.
2
votes
2answers
1k views

Grep for string in first line of all files in directory and descendants [duplicate]

How can I grep for a given string in all files in the current directory, and recursively so, only considering the first line? (the #! line, if present, but only if #! is in the -first- line)?
1
vote
2answers
2k views

How to run grep and show x number of lines before and after the match [duplicate]

grep returns just the line where it matched the regex and often what I want to really see is a few (say 2) lines above and below the matched one. Is there a simple way to achieve it? EDIT: OS: Ubuntu ...
1
vote
2answers
543 views

grep: invalid content of \{\}

Here's the command : grep '\(2\)[[:digit:]]\{\1\}' numbers What I want is to match exactly 2 digits after the digit '2', 3 digits if I change the digit '2' to '3' in my expression, 4 digits if ... ...
0
votes
3answers
215 views

For all files that does not contain a string, prepend a string to the file

I am trying to iterate through a list of html files, check to see if {% load static from staticfiles %} exists in the file and if it does not exists, prepend {% load static from staticfiles %} to it. ...
2
votes
2answers
812 views

Tail -f piped through grep not outputing to file, but outputs to console

I'm using the following command tail -f /mydir/myfile | grep "searchterm" >> outfile Without the -f it works fine, but with the -f, which I need, nothing is written to the file. The ...
12
votes
2answers
2k views

grep: Find all lines that contain Japanese kanjis

In a huge UTF-8 text file, I want to show all lines that contains Japanese kanjis. What grep (or other) expression does this? If I am not mistaken, kanjis are the characters between \u4e00 and ...
2
votes
3answers
453 views

How to make GNU grep the default in FreeBSD?

I'm running FreeBSD 9.1-RELEASE. I've installed GNU grep with portmaster textproc/gnugrep. However the "default" grep for users is still FreeBSD grep. # /usr/local/bin/grep -V /usr/local/bin/grep ...
1
vote
4answers
3k views

Getting a list of users by grepping /etc/passwd

For a homework assignment, I need to use grep to parse /etc/passwd and get a list of all users (their usernames only, nothing else). It should use a pipe, and the results should end up in the allusers ...
5
votes
4answers
20k views

List the files containing a particular word in their text

I would like to list the files recursively and uniquely that contain the given word. Example: Checking for word 'check', I normal do is a grep $ grep check * -R But as there are many occurrence ...
2
votes
2answers
204 views

using grep to show entries that match a pattern and are present at least X times

I have a file that have entries like this among other lines Feb 16 17:30:18 ns1 dovecot: pop3-login: Disconnected (auth failed, 1 attempts in 17 secs): user=<accountin@myserver.com>, ...
3
votes
3answers
61 views

How to separate numerical values from identifiers

I'm currently writing a shell script that seperate values from their identifiers (retrieved from grep). For example, if I grep a certain file I will retrieve the following information: value1 = 1 ...
2
votes
2answers
432 views

Matching two files for similar first line

I have 2 set of files. File one contains ID's ex: 1111 2222 6666 3333 4444 File two contains ID and username: 1873 Neil 1111 Roger 7632 Tim 3333 Oscar 8723 Greg 4444 Roy 6666 Patrick I want to ...
2
votes
8answers
1k views

grepping dotfiles with -R correctly?

From time to time I need to find a culprit in an unknown dotfile and instead of trying to figure out which package is to be blamed (e.g. xfce4 or thunar?) and what is their naming convention (.app vs ...
1
vote
1answer
841 views

Sorting by one column then the

Say i have a output file with following: 010513 08:04 ROUTER1 192.168.1.1 68.130.5.10 HIT(1) 010513 08:04 ROUTER1 172.168.1.1 28.130.5.10 HIT(1) 010513 08:04 ROUTER1 122.168.1.1 ...
3
votes
2answers
3k views

How to use tail -f with grep to show surrounding lines

I would like to see the output in a logfile greped by only one domain but also the following two lines. Example: tail -f /var/log/apache2/modsec_audit.log |grep mydomain.de this shows all lines, ...
3
votes
2answers
352 views

sort a file based on length of the column/row

I need to sort a file based on the number of chars in the first column. I have no idea on how to go about this. (On Linux, so sed/awk/sort is available). An example: .abs is bla bla 12 .abc is bla ...