grep is a command-line tool for searching text patterns in files
2
votes
2answers
116 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
80 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
108 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
108 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
100 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
89 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
83 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 ...
9
votes
2answers
249 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
124 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
votes
1answer
45 views
Doing regex in python [closed]
I had a directory "/pcap_test" which contains several log files. Each file has a pattern like:
Pkt: 1 (358 bytes), LIFE: 1, App: itunes (INTO), State: TERMINATED, Stack: /ETH/IP/UDP/itunes, Error: ...
1
vote
3answers
192 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
3answers
387 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
81 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
46 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
90 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
134 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
87 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 ...
1
vote
2answers
137 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, ...
2
votes
2answers
57 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
274 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
144 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
375 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 ...
2
votes
2answers
87 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 ...
2
votes
1answer
209 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
156 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
7
votes
2answers
205 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
234 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 ...
3
votes
4answers
555 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
158 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 ...
4
votes
2answers
172 views
how to use grep for specific files?
for example I type
ls -altr | grep "23 Dec"
so it will show files for 23 Dec only and I want to use grep for them, like
ls -altr | grep "23 Dec" | xargs grep -l "some_string"
but this doesn't ...
10
votes
6answers
321 views
How to find files with 100% NUL characters in their contents?
What is the Linux command-line command that can identify such files?
AFAIK the find command (or grep) can only match a specific string inside the text file. But I want to match whole contents, i.e. ...
3
votes
5answers
257 views
Search among the content of a large number of plain text files?
I have a directory with 1,242,276 plain text files on my external hard drive. They are totally unorganized with meaningless numbers as their file names. The reason for that is because they were ...
2
votes
2answers
254 views
extract last match from logfile till end
Using sed, grep, awk, or ruby, what's a simple way to find the last match of a string in a larger log file, and send every line following it (inclusive) to another file?
Example:
grep -A222 ...
1
vote
1answer
66 views
How can I find all matches of a string in a directory?
Using grep (or some other utility), is it possible to find all matches of a regular expression in a folder (searching the text of each file?) I want to find every match of the regular expression ...
5
votes
2answers
216 views
How do regular expressions differ from wildcards used to filter files
While we use * to denote zero or more previous characters in grep, we use *.c to find all C files when we use it with the ls command like ls *.c. Could someone tell how the use of * differs in these ...
0
votes
1answer
388 views
grep the only first word from output with grep -P
I'm trying to grep username users |grep "^\b\w*\b" -P how to do it with grep?
0
votes
1answer
73 views
What does this “matching lines means”?
The grep manual says "By default, grep prints the matching lines.". What does this matching lines says. When I tried its prints the whole paragraph containing the pattern.
0
votes
2answers
137 views
Sample file for grep
Can anyone please point to some good sample files that helps to learn grep. This is for academic use. It should be a large one so that students could understand its importance
1
vote
1answer
84 views
Display words in color
I am looking for a tool which takes a file in input and a word to search. It should display the file with color the words if it corresponds to the search.
Like grep --colors but displays all the ...
3
votes
5answers
124 views
grep device name and look for next value :
I have this output from a find command:
abc,10.11.13.14,def,1.2.3.4,geh,6.7.54.23
where abc,def and geh are device names and could be of any length and others are IP address belong to devices. ...
2
votes
3answers
824 views
Grep command to find files containing text string and move them
I am able to locate files in a folder containing a specific text string using this command:
grep -lir 'string' ~/directory/*
How do I move the files that appear in the above result to another ...
2
votes
1answer
107 views
grep all words with specified length, without letter x
So I am stuck here:
grep -E '^....c...c...$' shows all words with the expr I need. Now from this words I only need the ones that don't have a x.
Who can help me?
1
vote
3answers
119 views
How can I use grep to search for lines that start with a certain character in bash
I want an alias ('ggg') that will look through my existing set of aliases and tell me all the ones that begin with g. I have a lot of g* aliases :)
I tried this: alias ggg='alias | grep ^g' but ...
1
vote
4answers
897 views
How to print all lines after a match up to the end of the file?
Input file1 is:
dog 123 4335
cat 13123 23424
deer 2131 213132
bear 2313 21313
I give the match the pattern from in other file ( like dog 123 4335 from file2).
I match the pattern of the line ...
3
votes
1answer
381 views
Modify /etc/xdg/lxsession/LXDE/autostart before boot
I have some parameters that I would like to change in /etc/xdg/lxsession/LXDE/autostart, before it is run. I get the parameters from a grep command. I would like to feed them to the autostart file but ...
1
vote
3answers
139 views
grep how to suppress display of non-matched file?
I am trying to find files containing a specific word using grep. There are many files in the directory (> 500)
Command I run
$ grep 'delete' *
Output
validate_data_stage1:0
validate_data_stage2:0
...
1
vote
1answer
129 views
solaris + fit egrep for solaris
On Linux machines I use this syntax, in order to match all VALID ip's.
My question: what needs to change for egrep command in order to run the egrep on Solaris?
According to egrep manual page "-o" ...
1
vote
1answer
108 views
questions on find and grep
With respect to the following find command-line
find . -type f -exec grep -l strings {} \;
I do not understand the usage of -exec and {} \ Thanks.
1
vote
2answers
89 views
How to find which files contain mentions of a wildcard image name?
What I am trying to do is do a search on my server to find which files contain mentions of images with a certain keyword in the filename but all I can figure out is how to find the filenams (not image ...
9
votes
2answers
540 views
How to run grep with multiple AND patterns?
I would like to get the multi pattern match with implicit AND between patterns, i.e. equivalent to running several greps in a sequence:
grep pattern1 | grep pattern2 | ...
So how to convert it to ...

