I want to grep for 'AB...CDE', where ... stands for anythings until CDE first occurs.   I have tried grep 'AB*CDE' filename but this matches til the last occurrence of CDE.   How can fix this?  Suppose that my input is: JKIABTHIUCDELKJUCDE  and I want output as: ABTHIUCDE  which mean from AB until CDE
123694
I want to search for string that have  [RT]"anything"D  which mean first character can either be R or T  and the next can be anything until D is appear what should I use is it "egrep"?
40827
I use the grep command to search for a string in many files. Is there something similar to "search and replace"?
122315
I am using grep to recursively look through files and pull out all strings matching a pattern. I want to print the file path: matched string.   -H should print the file path for each entry  -o should print just the matched string, omitting everything else on the line I don't want  -r recursive search.   I run:  grep -Hro [pattern] .   Most of the matches print with the filename, however a few just print the matched string. Are -H and -o mutually exclusive in that -o is trimming the filename?  Sample Output:   ./path/foo.txt: foo ./path/bar.txt: foo ./path/baz.txt: foo foo ./path/baz.txt: foo   The 4th foo match should also have a file associated with it, but it is not being printed.   I am getting behavior similar to this , however I am using the -H flag, and the "/dev/null" solution does not work either.  $ grep --version grep (BSD grep) 2.5.1-FreeBSD   EDIT:  After further exploring each match where the regex was not getting the file name, they all occur when two strings are matched on the same line.  For example this text file  foo foo sometext foo foo   Outputs  ./path/foo.txt: foo ./path/foo.txt: foo foo ./path/foo.txt: foo   Anyone know a solution to get both matches to print a filename?
77187
Say I have a file:  # file: 'test.txt' foobar bash 1 bash foobar happy foobar   I only want to know what words appear after "foobar", so I can use this regex:  "foobar \(\w\+\)"   The parenthesis indicate that I have a special interest in the word right after foobar.  But when I do a grep "foobar \(\w\+\)" test.txt, I get the entire lines that match the entire regex, rather than just "the word after foobar":  foobar bash 1 foobar happy   I would much prefer that the output of that command looked like this:  bash happy   Is there a way to tell grep to only output the items that match the grouping (or a specific grouping) in a regular expression?
111466
Consider path in a directory structure  /A/B/C/D /A/B/C/E /A/B/O/P   now if I want to list all path which has sub directory C in it, then can it be done through grep? Expected output:  /A/B/C/D /A/B/C/E   I tried using grep and find but could not achieve this.
33685
Pretty basic question, I'm trying to write a regex in Vim to match any phrase starting with "abc " directly followed by anything other than "defg".   I've used "[^defg]" to match any single character other than d, e, f or g.  My first instinct was to try /abc [^\(defg\)] or /abc [^\&lt;defg\&gt;] but neither one of those works.
79289
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?
93644
If I search for multiple search strings in grep : usually just do:  grep "search1\|search2" somefolder/*.txt   but, what if I have 100 or more search strings? Can I say like this:  grep "stringPattern.txt" somefolder/*.txt   where stringPattern.txt is a file containing a list of words I need to search in *.txt.
48630
$ echo -e 'CH12\nCH23au' | sed '/^CH/s=^=&lt;b&gt;=' &lt;b&gt;CH12 &lt;b&gt;CH23au   I know I can match lines starting with CH by ^CH but how can I match multiple patterns?   Example:  Input:  CH12 CH23au   Output:  CH12 &lt;b&gt;CH23au   How to only put &lt;b&gt; where there is ^CH and au in the line?
3235
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 something like?  grep pattern1 &amp; pattern2 &amp; pattern3   I would like to use single grep because I am building arguments dynamically, so everything has to fit in one string. Using filter is system feature, not grep, so it is not an argument for it.    Don't confuse this question with:  grep "pattern1\|pattern2\|..."   This is an OR multi pattern match.
63735
I need to solve this in a shell script. I am counting number of occurrence of the abc string below and I want to get the answer as 3.    echo abcsdabcsdabc | grep -o abc   abc   abc   abc     Assuming we do not have the -o option in grep, how do we approach this then?
80943
I want to pipe file names to other programs, but they all choke when the names contain spaces.  Let's say I have a file called.  foo bar   How can I get find to return the correct name?  Obviously I want:  foo\ bar   or:  "foo bar"   EDIT: I don't want to go through xargs, I want to get a correctly formatted string out of find so that I can pipe the string of file names directly to another program.
193
I want to run a java command once for every match of ls | grep pattern -. In this case, I think I could do find pattern -exec java MyProg '{}' \; but I'm curious about the general case - is there an easy way to say "run a command once for every line of standard input"? (In fish or bash.)
37775
Between first occurrence of Cat to next occurrence of Cat, it should create a separate line with delimiter as ",".  File input  as below.  Cat AA BB CC Cat AA-1 BB-1 CC-1   Output expected:  Cat,AA,BB,CC Cat,AA-1,BB-1,CC-1
11784
I want to start grepping from the lines that has CK at the end of line and stop grepping when the line has D at the end. I tried grep "$CK" "$D" file..txt, but it didn't work.  Input:  kkkkkkkkkkk    jjjjjjjjjjjjjjjjjj   gggggggggggg/CK   JHGHHHHHHHH    HJKHKKLKLLL    JNBHBHJKJJLKKL   JLKKKLLKJLKJ/D   GGGGGGGGGGGGGG   GGGGGGGGGGGGGG   The desired output:  gggggggggggg/CK   JHGHHHHHHHH    HJKHKKLKLLL    JNBHBHJKJJLKKL   JLKKKLLKJLKJ/D
60761
I'm looking for the string foo= in text files in a directory tree. It's on a common Linux machine, I have bash shell: grep -ircl &quot;foo=&quot; *  In the directories are also many binary files which match &quot;foo=&quot;. As these results are not relevant and slow down the search, I want grep to skip searching these files (mostly JPEG and PNG images). How would I do that? I know there are the --exclude=PATTERN and --include=PATTERN options, but what is the pattern format? The man page of grep says: --include=PATTERN     Recurse in directories only searching file matching PATTERN. --exclude=PATTERN     Recurse in directories skip file matching PATTERN.  Searching on grep include, grep include exclude, grep exclude and variants did not find anything relevant If there's a better way of grepping only in certain files, I'm all for it; moving the offending files is not an option. I can't search only certain directories (the directory structure is a big mess, with everything everywhere). Also, I can't install anything, so I have to do with common tools (like grep or the suggested find).
75552
I'm trying to grep for the full sentence containing a search term. I've tried  grep (^.|\.\s).*searchterm.*(\.\s|\n)   but it's not working and I'm not sure why.  To clarify: I want stdout to print the full sentence of the search term. I am using grep to search through a single text file.  As an example, if my file has  "Foo blah. Blah blah searchterm blah blah. Foo bar."  I want stdout to print Blah blah searchterm blah blah