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

learn more… | top users | synonyms

3
votes
4answers
2k views

Compare two text files and find matching lines

I have two files A and B. A looks like this (4 to 6 lines): GAGA CAGA GGGT TATT file B is a really big file with thousands of lines, here is a short example: AAATGTCAAGAGACAGAAATGTCAAGAGGGT ...
1
vote
2answers
67 views

Egrep multiple strings in an XML file

I have a collection of XML files in a standard format that I'd like to search to see if they match two strings. Here is the idea: <ELEMENT1>Dave</ELEMENT> ...
6
votes
2answers
518 views

What's the most efficient way to grep for two completely separate things and assign the values to separate variables?

CentOS 6.x I want to take the output from curl, grep for two completely separate strings, and assign their respective values as variables. What is the most efficient way to do this (without writing ...
4
votes
2answers
381 views

how to make alias to make grep command shorter [duplicate]

In my coding, I always do grep -rnIi "abcabc" . --color But, how to make an alias that can let me type only one word with my search string? Is that possible?
1
vote
2answers
472 views

Redirect grep error output to file

I wanted to capture to a file the errors being returned on the command line from grep. For example, grep foo.lookup No such file in directory I want to output that to a log file. This is my shell ...
0
votes
2answers
99 views

How to extract submatches from a string and write those to a file?

I want to parse a string for specific submatches and output those - one submatch per line - into a file. Essentially I would like to extract the value of each href-attribute: $ cat Fin <a ...
0
votes
2answers
272 views

Using grep to find first two numbers of IP addresses?

I'm trying to figure out how to use grep to pull out only the first two numbers of an IP address in a list. I've got a routine that is isolating the log entires (from Exim) that I need, now I just ...
4
votes
2answers
618 views

Why pidof and pgrep are behaving differently?

I have a init script in /etc/init.d/myservice for initialize a service like this: ... start() { ... daemon /usr/sbin/myservice ... } stop() { ... pgrep myservice pidof myservice ps -ef ...
1
vote
2answers
106 views

Emacs temp dot hash file don't exist

I use find | xargs grep a lot when working on large source code and when I didn't save a file in Emacs it creates .#SomeFile and grep give error that there's not such file (I'm not including because ...
0
votes
3answers
203 views

How can I use grep to search a file for string combinations?

What I'm trying to do is use grep to search my Apache logs. What I want is to find is every entry from a certain IP address that also has .html or .php in the line. In other words, I want to see what ...
0
votes
2answers
79 views

How to match stream against white-list and black-list?

How can I duplicate a pipe stream (output from another program) so that for every line, I can check whether it matches independent regular expressions (ideally, reuse a grep command with options like ...
20
votes
6answers
4k views

Regex for all 10 letter words, with unique letters

I am trying to write a regex that will display all words that are 10 characters long, and none of the letters are repeating. So far, I have got grep --colour -Eow '(\w{10})' Which is the very ...
0
votes
1answer
64 views

Limiting grep search

Please help! Must use grep for this assignment. Must control grep function to search for a string strictly in a given field (Sadly no delimiters) Search field is characters 12-26. Must check if user ...
1
vote
3answers
43 views

My grep (GNU grep) 2.5.1 does not obey backslash character and special expression

I'm trying to follow a section in The GNU Grep Manual but my expression isn't working. Is it my grep version? Red Hat 5.5. $ rm file $ echo 'hello world' > file $ grep 'hello world' file hello ...
2
votes
3answers
571 views

How to show CPU time for processes via top without 'root' procs

Okay, So I've been attempting this for about three hours now without success. How do you search/display/use the top command (or ps command if it works...) to output a list of all procs, sorted by CPU ...
5
votes
3answers
128 views

grep command giving error

I am using grep to filter out the contents on some patterns(genes in my case). For more info,here is the earlier link. Find pattern from one file listed in another My code(should work) but is not. ...
0
votes
4answers
58 views

Grep files excluding few files names

I have a folder who have files names according to date for one month i.e. AP_20140101.gz, AP_20140102.gz, ... for each day. Here 2014 is year, 01 is month and 01 is date (AP_YYYYMMDD.gz is general ...
3
votes
2answers
168 views

How can I open a file that results from grep?

I often grep a bunch of files to find a line, and then grep returns one result. Rather than copying and pasting the filename into a new command, I'd like to be able to open that one result with an ...
2
votes
1answer
159 views

Find pattern from one file listed in another

I want to find patterns that are listed in one file and find them in other file. The second file has those patterns separated by commas. for e.g. first file F1 has genes ENSG00000187546 ...
1
vote
3answers
55 views

Use Unix tools to look for a definition block in an XML.

I am using an XML that has definitions in this form - <definition name="ticketOpen" extends="ticketUpdate"> <put name="title" value="Open Ticket" /> <put name="mainForm" ...
0
votes
1answer
86 views

Lynx incremental search

I am trying to run an incremental search using lynx. Imagine a page, for example, an index_of page which contains several folders which also contain other subfolders and files. I want to run lynx in ...
1
vote
1answer
258 views

how do i redirect output from tailf & grep to a file [duplicate]

All I wanted is to grep for specific lines in an ongoing log and re-direct it to some file.. tailf log | grep "some words" Now, I want the above command output to get re-directed to some file in ...
0
votes
4answers
85 views

What are alternative tools for searching files in full content?

I realized that most of the text related tools I use, grep/egrep/awk/sed are line-oriented. I guess that is a simplified approach to search in files but I was wondering if there is another set of ...
1
vote
2answers
162 views

comparing user given time for log file time

Apologies straight away for bad-styled-question-and-heading.....learning unix and its command these days, m trying to figure out a solution for below scenario : Lets say i have a log file which ...
-2
votes
1answer
33 views

Implementation Logic [closed]

I have two files,which is something like this: file1 msgid "New" msgstr "" dsvhuvchvdhcvhc msgid "Old" msgstr "hsvhs" kdnvcjdbvj msgid "Bold" msgstr "" file2 dcbjdsbc msgid "New" msgstr "Alas" ...
0
votes
1answer
32 views

Help on editing a script using grep and sed

First I'm new to unix so excuse my simple question, also be aware that I work on AIX. I have a lot of sql files that contains the following string: ${DB_USERNAME}.${TABLE_NAME} Can anyone please ...
-1
votes
1answer
675 views

Display column that has a specific string

Content of a sample file is as follow: AA BB CC DD BB 1 2 3 4 9 5 6 7 8 10 I want to display the whole columns that contain BB and DD. In the real case, I do not know which columns contain ...
0
votes
1answer
58 views

Need to grep for specific lines from ongoing log and save it in some file

So, let me start with the overall outcome that i want to achieve. There is just one log, which will have info on certain devices, that i am upgrading. I use "tailf log" to monitor the log. Now, ...
1
vote
1answer
105 views

pcregrep fails due to segmentation fault

I am extracting the HTML source of a web page using the below command. curl http://www.linkedin.com/pub/ramesh-venkataraman/63/621/b42 -s | w3m -dump -T text/html > foo.txt The foo.txt has the ...
3
votes
3answers
2k views

extract only the substring after double quotes - grep

I have a file which is as below. <a href="http://firstlink.com" title="title1"> <a href="http://secondlink.com" title="title2"> <a href="http://thirdlink.com" title="title3"> <a ...
5
votes
1answer
212 views

counting multiple patterns in a single pass with grep?

I've written a grep loop to iteratively count DNA trinucleotides within a gzipped DNA fasta file containing DNA sequences e.g. declare -a tri=(AAA AAC AAG AAT CAA .. etc) for i in ${tri[@]} do ...
6
votes
4answers
3k views

How to find a file in Linux with its path?

I am trying to find settings.xml file in my Ubuntu machine. I have no clue where it is, and which directory it is in. I tried using this - ls -R | grep settings.xml But it doesn't show me the ...
1
vote
1answer
152 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
300 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
78 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
154 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
195 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
62 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
257 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
270 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
2k 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 ...
11
votes
4answers
7k 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
150 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 ...
4
votes
1answer
140 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
543 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
99 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
700 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
28 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
364 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: ...