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

learn more… | top users | synonyms

3
votes
1answer
105 views

What's the difference between \b and \< in the grep command

In the man page of grep, I see The symbols \< and \> respectively match the empty string at the beginning and end of a word. The symbol \b matches the empty string at the edge of a ...
4
votes
2answers
431 views

To grep 20 characters after and before match

I have the problem that I get too much information after the match for grep -RnisI --color=auto "pseudomonas" * I want to get only like 20 characters or 10 words after and before the match. What ...
0
votes
1answer
36 views

echo keywords found

I'm trying to figure out which keywords are being found for [each] file in the script below. I tried adding echo $keywords and it just outputs every keyword. Code: keywords=("Alachua" "ALACHUA" ...
6
votes
6answers
3k views

bash find lines starting with string

I have a bunch of files and I want to find which one contains sequential lines starting with a certain string. For example for the following file : Aaaaaaaaaaaa Baaaaaaaaaaa Cxxxxxxxxx Cyyyyyyyyy ...
3
votes
4answers
147 views

Identifying genes from a list of genes

I have a gene list file. Some thing like this SWT21 SSA1 NRP1 EFB1 TFC3 MDM10 I have another file which also contains the names of these genes in my list along with other ...
2
votes
1answer
72 views

make grep confirm all matches

I am writing a "unit test" for a bunch of .tex files and want to check for incorrect entity names, e.g. "Data Items" instead of "DataItems". Currently, I use grep to search for the incorrect ...
4
votes
4answers
2k views

Grep for range of numbers [duplicate]

How would you search a log file for a date range? Log file looks like this: 01/14 00:00:01 INFO: received connect request from 10.10.10.10 I need to condense the log to 10 minutes starting ...
2
votes
5answers
187 views

grep change of line followed by a variable

I have a file of the following form (with '-' serving as delimiters), and I want to find the appearance of a number only when it follows a delimiter. I suppose it's a concatenation of grep '-\n' and ...
0
votes
2answers
63 views

How to search '(+1)' character substring in a string

I want to search for (+1) in a string (which is a GDG dataset name to confirm if it is a GDG) and want to get a binary answer if it has (+1) as part of the string or not. Can some one please help?
2
votes
2answers
174 views

grep and directories containing spaces

I would like to search all files containing an association of strings (here the files should contain 'arthur' AND ('déni' OR 'deni') for instance) in a directory and subdirectories. After some search ...
2
votes
5answers
138 views

identifying words in file 1 and matching them to second file and printing them

I have two files as follows File 1 has list of Ids ram Tarah taikah jhdfklj File 2 has id=ram;*between*hkjhdswklf kjsdklhglshglkhgklsdgkhdfg id=taikah;jhdjfkhg**kjdfkjksfdjk ...
2
votes
2answers
210 views

filter and count with grep in a single pass?

I am using grep at the end of a set of piped commands to filter some rows out of a file. Afterwards I will want to do some arithmetic based on the number of remaining rows. e.g. ...
1
vote
1answer
161 views

Can we make grep faster by indexing words in files? [duplicate]

Over a decade ago I imagined an improved version of grep that would use indexes to make recursive searching faster. I never got around to writing it, but I wonder if somebody else did! My original ...
1
vote
1answer
525 views

grep ipaddress in expect script

this is part of code, expect script and I have problem with greping ipaddress from file wich is assign to variable $filename.This is the code: #!/usr/local/bin/expect -- ###Made by Etihkru#### ...
0
votes
4answers
141 views

Grep searching for files which are not existing

I wanted to search for the text " Starting kernel" in a directory, so I did this: [root@xilinx petalinux-v2013.10-final]# grep -r "Starting kernel" grep: warning: tools/packagemanager/lib/i686: ...
2
votes
3answers
57 views

How to list backup files missing corresponding real files?

I accidentally deleted some files spread across my home directory, but I do not know exactly which ones were removed. How can I get a list of all backup files missing their corresponding file? ...
4
votes
3answers
280 views

Search for specified keywords in files and copy to a new filename based on the keyword

I'm trying to create an .sh script where if any keyword is found in a file then copy that file to the directory /pathtofolder/keywords/$thefirstkeywordfound (overwrite the file if it already exists). ...
3
votes
2answers
182 views

How to use restricted characters in egrep?

I'm trying to use a regex in egrep on Centos 5.10, based on the one I made from this question on SO. T12345 .{1,100}[\n\r].{1,100}2014.03.04 I can successfully match the regex to the content in my ...
3
votes
1answer
98 views

Is there any drawback to using “grep -E” instead of plain “grep”?

I understand that GNU grep without -E uses basic regex and that grep -E uses extended regex. Is there any harm in using grep -E even for situations that would work with plain grep?
2
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
62 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
433 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
312 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
329 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
88 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
244 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
484 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
95 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
151 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
74 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
61 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
40 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
410 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
54 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
129 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
117 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
53 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
74 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
211 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
79 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
138 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
32 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
31 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
407 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
53 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
88 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
1k 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
168 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 ...