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

learn more… | top users | synonyms

1
vote
2answers
84 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
103 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
67 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
3k 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
38 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
289 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
125 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
51 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
113 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
97 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
49 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
69 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
174 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
74 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
120 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
31 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
251 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
48 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
80 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
930 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
146 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
754 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
81 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
127 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
74 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
116 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
152 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
51 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
181 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
181 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
4k 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
144 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
134 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
411 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
73 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
415 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
25 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
233 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
63 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
1k 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
439 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
151 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
105 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
116 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, ...
0
votes
1answer
872 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
318 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 ...