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

learn more… | top users | synonyms

0
votes
3answers
3k 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
110 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 ...
14
votes
1answer
5k 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
331 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
1k 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
498 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
293 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
892 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
102 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
144 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
327 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
594 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
8k 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
112 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
245 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
727 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
300 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 ...
1
vote
3answers
11k 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
507 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
992 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
325 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
633 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
223 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. ...
3
votes
2answers
1k 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
497 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
4k 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
27k 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
212 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
62 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
458 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
2k 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
978 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
4k 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
405 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 ...
1
vote
2answers
1k views

Parsing string by awk and get only elements without pipes or semi colons

I would like get this string line AUGUSTYN|Stanisław|3589238 without | and : I tried something like that: cat baza|grep "AUGUSTYN" -n|awk -F '|' '{print $1,$2,$3,$4}'` (baza is my file with ...
3
votes
2answers
353 views

Please explain the -f option in pgrep

man pgrep says the following about -f option: -f The pattern is normally only matched against the process name. When -f is set, the full command line is used. What does it ...
2
votes
2answers
3k views

grep multiple strings, count lines, echo output for each string

I have a directory of files that is structured like this: data/directory1/file1.xml data/directory2/file2.xml data/directory3/file3.xml ... There are thousands of sub directories within data/, each ...
3
votes
2answers
1k views

grep only subdirectories matching pattern

I have a directory tree consisting of several thousand subdirectories, but I frequently need to grep only a small subset of those directories. How can I grep only those subdirectories matching a ...
6
votes
1answer
7k views

How to grep lines which does not begin with “#” or “;”?

I want to grep smb.conf and see only lines which are not commented.
-2
votes
4answers
352 views

How to grep number of occurence of two different words in a file on Linux?

How to grep number of occurrence of two different words e.g. 'register' and 'evn' in a file on Linux ? The output should be like following: registered:20
9
votes
2answers
848 views

“grep -r foo *” vs “grep -r foo .”

When using grep -r you could search in all files with either * or . and it seems to return the same thing but is it really the same? Let's say I search for "foo", then I could write grep -r foo * ...
-1
votes
2answers
2k views

Meaning of asterisk (*) in grep

[USERNAME@host ~] echo -e 'prdxxx\ndadxxx' | grep "da*xxx" prdxxx dadxxx [USERNAME@host ~] echo $SHELL /bin/bash [USERNAME@host ~] dpkg -l | grep -iw bash ii bash ...
5
votes
4answers
15k views

grep lines starting with “1” in Ubuntu

I try to search for lines that start with "1" using ls -1 | grep ^1* but it returns lines that do not start with 1. What I am missing here?
3
votes
5answers
475 views

Print non-existent files from a pipe input

I have a directory of lots of .PDF and .JPG files. There should be a .JPG file for each .PDF with the same name. I'm trying to use a command to find .PDF files that doesn't have a .JPG file. My ...