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

learn more… | top users | synonyms

3
votes
3answers
60 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
231 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
420 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
574 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
1k 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
221 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
552 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
252 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
1k 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
506 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 ...
3
votes
1answer
2k 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
268 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
462 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
1k 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 ...
4
votes
4answers
4k 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
307 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
490 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
5answers
723 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
342 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
816 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
82 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 ...
4
votes
2answers
542 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
1k 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
97 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
175 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
139 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
171 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
4k 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
159 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
490 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 ...
2
votes
5answers
3k 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
750 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
402 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
187 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
125 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 {} \.
1
vote
2answers
170 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 ...
10
votes
2answers
2k 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 ...
3
votes
5answers
1k views

Output multiple files from a single grep?

I'm not very experienced in shell scripting, but I'm trying to understand how to grep for a pattern and for each file where there is a match write a file to disk that contains the matched line from ...
2
votes
3answers
2k views

grep for capital words

I have a file that has declarations in it with capital words, something like: public final Foo BAR; these declarations are not all uniform. Is there a way for me to grep out just the capital ...
7
votes
3answers
1k views

Mark occurrences of keyword with a different color

I have a program which spits out an output to stdout like: [OK] Something is ok [OK] Something else is also ok [FAIL] This does not look good [FAIL] Neither does this [OK] At ...
1
vote
1answer
601 views

Using grep command and backreferencing

This is a pretty basic question, but I can't get my head around it. I'm learning Linux and one of the questions i've been given is; *The word sentimentalment includes the same three characters ...
0
votes
1answer
760 views

Problem with using grep command with env variable containing special characters

I have a variable "abc" with value "xyz*!@#" in my unix account (ksh). I used export command to export this variable into the environment. When I use grep command as below env |grep xyz I get the ...
4
votes
2answers
3k views

How to return both file name and line number with find … -exec grep?

When using find, how do I return the file name and the line number when searching for a string? I manage to return the file name in one command and the line numbers with another one, but I can't seem ...
1
vote
3answers
2k views

Linux: Does find | xargs grep have limitations?

I've historically performed something like: find . 2>/dev/null | xargs grep -i something_to_find 2>/dev/null If my pwd is barfoo (/foo/bar/baz/foofoo/foobar/foobaz/barfoo) it finds matches. ...
2
votes
3answers
399 views

Regex/pattern matching problem to extract data

What is the best way to remove distances in the following lines and output cdv format. Can this be done reasonably easily on the command line? I'd like to avoid having to write a full-blow script. ...
4
votes
4answers
351 views

Most efficient grep method

Currently I am grepping data from a file containing any of the following: ...
2
votes
3answers
385 views

Extract integers enclosed in round brackets

I'm new to Linux. I've a file which contains list of movie names and their release year. I want to list out all release years. Specifically my file looks like below TDKR(2012) Vicky Cristina ...
2
votes
2answers
421 views

Parse apache logs to exclude IP ranges

I need to look for some requests in a huge pile of apache logs. My only requirement is this: I need to only view the requests coming from any IP address that is NOT included in a list of 50 IP ranges ...
1
vote
2answers
185 views

Match a simple Regex

I need to match this: (tt\d{1,10}) in a file with the file ending txt. I have tried grep and ack-grep but without results. ack-grep -G \.txt$ -g "(tt\d{1,10})"
2
votes
3answers
3k views

solaris 10 + display 2 lines after match by grep?

I want to match for example: The string e1000g0 from the lltconfig -a list , and then to display the two lines after the string e1000g0 so I get only the lines: Node 0 du1a : ...