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

learn more… | top users | synonyms

1
vote
1answer
107 views

grep to ignore patterns

I am extracting URLs from a website using cURL as below. curl www.somesite.com | grep "<a href=.*title=" > new.txt My new.txt file is as below. <a href="http://website1.com" ...
0
votes
2answers
162 views

grep command in curl

I am trying to extract some URLs from a web page using cURL command. Initially, I use the cURL command as below. curl www.website.com/ Now, the website contains links to some other websites which ...
1
vote
3answers
75 views

sed or grep to get only the values without numbers

I have a file like below. 1. VMware ESX 2. SCCM 3. Healthcare Information Technology 4. vSphere 5. Citrix Metaframe 6. IT Service Management 7. ITIL 8. Active Directory 9. Project Portfolio ...
0
votes
3answers
1k views

grep to extract substrings in a string

I have an output for a command as below. Heading1 I am one value. I am another value. I am third value. Heading2 I am some value. I am someother value. I am new value. Heading3 ...
5
votes
1answer
127 views

grepping foo and bar

I am looking for a command options for grep to find files with the occurences of foo and bar. Grepping with grep -r -e foo -e bar . shows files which have only foo or only bar and files which ...
3
votes
1answer
177 views

find/grep outputs two lines for each file it finds match

I search my code base to find string patterns and list all the files where the pattern is found but only the file and not the lines on which it is found: find . -name *.java -exec grep -l 'someText' ...
1
vote
1answer
54 views

Restricting grep's --color option to the interactive shell

I have the following variable I want to set to make grep behave a certain way: GREP_OPTIONS=--color=always The problem is, I only want this environment variable to be set on the command line. I ...
7
votes
2answers
208 views

Using empty line as context “group-separator” for grep

I need grep output with context, in color, and blank lines as group separator. In this question, I learned how to define custom group-separator, and I have constructed my grep command like this: grep ...
0
votes
2answers
217 views

Exclude files that have very long lines of text from grep output

I often run grep commands to find things in my code, but the problem with web projects is that there will often be compressed JavaScript and CSS files which create one huge line of text, so that if a ...
8
votes
4answers
1k views

Grep from the end of a file to the beginning

I have a file with about 30.000.000 lines (Radius Accounting) and I need to find the last match of a given pattern. The command: tac accounting.log | grep $pattern gives what I need, but it's too ...
9
votes
4answers
5k views

How can I “grep” patterns across multiple lines?

It seems I am misusing grep/egrep. I was trying to search for strings in multiple line and could not find a match while I know that what I'm looking for should match. Originally I thought that my ...
3
votes
2answers
145 views

How much text does grep/egrep consume each time?

I'm confused on grep/egrep. These tools match a single line I think? In some cases I have heard "logical" line. Questions Is it correct to assume that essentially grep/egrep always processes a ...
3
votes
1answer
135 views

Why does grep treat '[D]ebug' string differently?

I've created simple text file named "T" to test the unusual behavior of grep: 1 Debug 2 debug 3 determined 4 Determined Tried different syntax: $ grep De T 1 Debug ...
0
votes
3answers
469 views

Awk/grep/sed get comma separated list of numbers from lines of text

I have a log file that has lines that look like this: blah blah blah Photo for (702049679 - blah blah blah Now I know I could get all the lines like that from the file by doing: grep "Photo for" ...
0
votes
3answers
86 views

grep for string like xxx12345

I have 64 processes running that have the following string pbs_mom -m -M 1234 -R 5678 -A foo12345 -c /var/spool/torque/mom_priv/login_config I need to search and extract just foo12345 always ...
0
votes
2answers
549 views

How to do max-depth search in ack and grep?

Is there any way to tell ack to only search for text on the current folder? (or specify a max-depth level?) And with grep?
2
votes
3answers
26 views

Move line from output to the front of output or custom reordering

I have a command find "$PWD" -name __openerp__.py|awk -F/ -vOFS=/ 'NF-=2'|sort -u and I want to take a certain line containing /web/addons and push it to the front of output then do the same with ...
2
votes
2answers
293 views

How do I check that a filename conforms to a pattern?

I'm tasked with writing a shell script which checks that a filename conforms to a specific pattern and I'm not sure how to go about it. The filename should follow a pattern which looks like: ...
2
votes
1answer
66 views

using grep --perl-regexp

this is a sample output of ls $ ls -lAF -rw------- 1 martin martin 168 Jan 25 23:26 aaa -rw------- 1 martin martin 168 Jan 25 23:26 bbb -rw------- 1 martin martin 168 Jan 25 23:26 ccc I would ...
1
vote
7answers
2k views

Sed / Awk - Find string exactly n characters long

Looking through the man pages for sed, awk and grep, I'm unable to find a way to search for a string that is exactly n characters long. Given the following text file, I want to extract just ...
4
votes
1answer
588 views

Using Modifiers of Perl-compatible Regex (PCRE) in grep

According to grep --help and man grep, we can use the -P option in order to interpret the pattern as a Perl regular expression (PCRE, to be precise), instead of the default POSIX basic regular ...
5
votes
5answers
161 views

A shell script to write selected fields to a single line

I have a log file trace.log which prints the time stamp, thread name and Transaction method and transaction ID as below. 2014-01-23 15:50:41,724 [catalina-exec-35] INFO TRANSACTION getConnection ...
3
votes
1answer
106 views

Can someone clarify this Bash script

I'm learning something about Bash scripting, and I came across this example: The task is to write a Bash script that reads a file, given with the first argument, pulls out those records that have the ...
1
vote
2answers
143 views

Why is my grep + regex not working?

I recently decided that enough was enough -- I was going to learn to use grep fluently. It's been all of three hours and I'm already stumped by this toy problem. I'm currently syncing a RAID5 array, ...
2
votes
1answer
1k views

find + grep to match exact keywords in a file

My script is not matching exact words only. Example: 12312312Alachua21321 or Alachuas would match for Alachua. KEYWORDS=("Alachua" "Gainesville" "Hawthorne") IFS=$'\n' find . -size +1c -type f ! ...
3
votes
2answers
407 views

grep string from contents of file command then delete file

I have a peculiar problem I need help with. I have a large batch of .docx files where a certain number of them are junk. I know how to identify these files from the file command, as they contain the ...
10
votes
3answers
819 views

grep to find instances of “Foo” where “Bar” does not appear within 10 lines

Suppose I want to search an entire tree for all CPP files where "Foo" occurs. I might do: find . -name "*.cpp" | xargs grep "Foo" Now suppose I want to list only those instances where some other ...
1
vote
2answers
304 views

How do I grep a file in a smb mount point without using mount or fstab?

I don't have permission to mount a smb share with the mount command or by using /etc/fstab, but I'm able to use the smb protocol in Nautilus (smb://10.1.1.1/share), for example ... s Is it possible to ...
2
votes
2answers
84 views

help with truncate \ find

This command won't work: $ truncate -s 0 $(find . -size +1c type -f -exec grep -LwE 'keyword1|keyword2|keyword3' {} +) "find: paths must precede expression: type Usage: find [-H] [-L] [-P] [-Olevel] ...
2
votes
4answers
404 views

Using wget and grep to download HTML pages and filter by keywords

KEYWORDS=("dolphins" "fish" "dogs" "cats" "iguanas") IFS=$'\n' find . -type f -size +1c ! -exec grep -qF "${KEYWORDS[*]}" {} \; -exec truncate -s 0 -f {} \; If a file is over 1 byte, search for ...
3
votes
2answers
1k views

test if return true if grep on output has string in one line

I just want to return true or false if a service is running. Here is where I'm at, not first try or last but current at writing: service iptables status | grep -qi "not running" The sdtout for ...
5
votes
3answers
164 views

Mac OS X find/grep generating “unknown --devices option”

I am entering a command I have done often with Linux, Unix perfectly fine but with Apple Mac OS X 10.8 (and probably before) I get a grep: unknown --devices option when I attempt to run the following ...
5
votes
5answers
339 views

Number of files not containing given string

I read the question about how to find out the number of files that contain a certain string. This is possible with grep -l "string" * | wc -l. Is it possible to invert this, finding the number of ...
2
votes
4answers
146 views

Print the string between two parentheses

I have file with these lines G8 = P(G1,G3) G9 = P(G3,G4) G12 = P(G2,G9) G15 = P(G9,G5) G16 = P(G8,G12) G17 = P(G12,G15) I need the output as G1,G3 G3,G4 ..... How can I do it with sed/grep ...
3
votes
1answer
140 views

Grep perl syntax and copyright character

I am trying to pull some links out of text that I downloaded of off the internet using grep, but keep getting "Aborted (core dumped)". When using grep I tend to use -P as I prefer to use perl syntax ...
1
vote
2answers
129 views

How to bury an invisible mark into lines of text?

How can I bury an invisible mark into random lines of text? Such a mark has to be there, though it will be invisible to someone reading that text printed out on the console. I want to identify those ...
-5
votes
1answer
95 views

Copy content of an file “passwd” to an file userlist.txt [closed]

The problem is that the file passwd hasn't got any tag like .txt or so. So I can't copy the content by passed > userlist.txt.
2
votes
2answers
80 views

Pipeline with grep and find prints numbers infront of result

Am using the following "find" command to extract some files, find /lag/cnnf/ -maxdepth 3 -newer ./start ! -newer ./end | grep -nri abc | egrep '([^0-9]45[^0-9])' | grep -nri "db.tar.gz" >> ...
1
vote
1answer
116 views

Grep for single and double digit

i have path name as below, abc4/2012 abc4/2013 abc45/2014 abc45/2014 When i grep for 45 it is showing one instance of 4 and for 4 its showing all 45. i need to grep both single digit and double ...
0
votes
3answers
132 views

Ignore lines containing a capital letter

Why does the following command still return some lines containing a capital letter? aspell dump master | grep ozz | grep -v '[^A-Z]'
16
votes
9answers
1k views

Grep lines but let the first line through [duplicate]

Consider the following output from df. Filesystem Size Used Avail Use% Mounted on /dev/sda1 23G 6.1G 16G 29% / udev 10M 0 10M 0% /dev tmpfs 397M 420K ...
3
votes
3answers
288 views

Grep command in shell script

I've been writing a shell script which should make grep command outputs for further use. However when I pass a variable containing ~/.../multiple_dir/* to grep as input I get empty output file. ...
4
votes
1answer
304 views

Grep multiple pattern negative match

So I have a bunch of Apache logs with using the standard log format. I want to get all the log lines that did not come from a web crawler. So lets say I have a file robot_patterns with entries like ...
4
votes
4answers
2k views

How can I suppress output from grep, so that it only returns the exit status?

I have the grep command. I'm searching for a keyword from a file, but I don't want to display the match. I just want to know the exit status of the grep.
4
votes
1answer
1k views

Why does grep sometimes show the file name, sometimes not?

Can somebody please explain to me why I don't get the full path in example 1? example 1 - returning found line grep MODIFY /opt/releases/packages/cr_c_cr6/sas/dbms/*/*; outcome: MODIFY example 2 ...
2
votes
1answer
54 views

Matching two different lines that are at least N lines distant from each other

I would like to match files that contain try (in one line) and consecutive catch (in another line) at least N lines later (to find very long try-catches and try to get rid of them). I mean, the first ...
24
votes
3answers
545 views

Multicolored Grep

I'm trying to get each grep command to highlight it's results in a different color. I can do it manually with a line like this: ls -l GREP_COLORS='mt=01;32' grep c | GREP_COLORS='mt=01;31' grep o | ...
1
vote
1answer
80 views

Help understanding an egrep expression

I stumbled across the following egrep expression: egrep '^([^aieou]*[aieou]){5,7}[^aieou]*$' /usr/share/dict/words on this page: http://matt.might.net/articles/sculpting-text The expression is ...
0
votes
1answer
96 views

What does Grep */* mean in KSH

In ksh, what does grep */*[myPattern] mean?
2
votes
2answers
2k views

grep: regex only for match anything between parenthesis

How do I match word only between parenthesis Input : this is (test.com) Desire Output : test.com