I'm playing with the Linux terminal and I have to do a exercise which states that I have to find inside a file for any line that contains at least an a, b and c, it doesn't matter it the lane has 2 a, 1 b and 1c or 1 a, 55 b, and 3 c. Like I said it needs to have at lest one a, one b and one c.  Example:  Input:  aaaaaaaaaaaa bbbbbbbbbbbb cccccccccccc abcabcabcabc hhahhhbhhhhc aabbccpppppp thisisrandom nononononono aandbandcnoo dddddddddddd   Output(valid):  abcabcabcabc hhahhhbhhhhc aabbccpppppp aandbandcnoo   All the content are inside a .txt file.  Edit: It needs to be done with a regular expression and metacharacters
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.
111755
I have a file with hundreds of paragraphs of around 15 lines each. I need to search for a pattern, say Occurrence: 1. If this pattern is found in the para, I need to print the entire paragraph. Note that the paragraphs are separated by 2 new line characters.  I have tried the below line of code and this obviously prints the first occurrence in the file. I am somehow unable to use a loop and print all such occurrences.  sed -n '1,/Occurrence: 1/p' ystdef.txt | tail -9 &gt; ystalarm.txt   Can I use the g (global) flag with sed to make this work? If yes, how?  Note that I am aware of the grep -A/B/C commands but they wont work on my Cygwin terminal.
34800
I want to find all files which contain a specific string of text. The grep command works, but I don't know how to use it for every directory (I can only do it for my current directory). I tried reading man grep, but it didn't yield any help.
34780
I want to know which files have the string $Id$.  grep \$Id\$  my_dir/mylist_of_files   returns 0 occurrences.  I discovered that I have to use  grep \$Id$ my_dir/mylist_of_files  Then I see that the $Id is colored in the output, i.e. it has been matched.  How could I match the second $ and why doesn't \$Id\$ work.  It doesn't matter if the second $ is the last character or not.  I use grep 2.9.    Before posting my question, I used google...       To search for a $ (dollar sign) in the file named test2, enter:      grep \\$ test2      The \\ (double backslash) characters are necessary in order   to force the shell to pass a \$ (single backslash, dollar sign) to the   grep command. The \ (single backslash) character tells the grep   command to treat the following character (in this example the $) as a   literal character rather than an expression character. Use the fgrep   command to avoid the necessity of using escape characters such as the   backslash.   but I don't understand why grep \$Id works and why grep \\$Id\\$ doesn't.  I'm a little bit confused...
112469
Say, I have some files, and I want to find the files among them which contain a string but do not contain another.  grep being line based, conditions such as grep -q printf file &amp;&amp; grep -vq '#include &lt;stdio.h&gt;' file will not work.   How should I go about doing this?  (I am on Debian, so answers specifically targeted at GNU versions of tools are fine.)
30572
Is there any tool that can get lines which file A contains, but file B doesn't? I could make a little simple script with, e.g, perl, but if something like that already exists, I'll save my time from now on.
82128
NOTE: This question is the complement of this Q&amp;A:     I need to get only the lines from a textfile (a wordlist, separated with newline) that has a length range of minimum or equal than 3 characters, but not longer or equal than 10.   Example:   INPUT:   egyezményét megkíván ki alma kevesen meghatározó   OUTPUT:   megkíván alma kevesen   Question: How can I do this in bash?
86509
I am trying to find data from files using grep, but grep usually prints out the filename as well as the line where the term is found.  In this case, I am looking for a special regexp and I want grep to print all items matching the regexp, not the line or the filename. In other words, I want to see only the matched regular expression.
104529
I have seen this construct in scripts a lot and used it myself, but it bothers me that I can't seem to find it in the documentation.  Example:  [ -f file1 ] &amp;&amp; [ -f file2 ] &amp;&amp; echo "Both files exist." || echo "One or the other file doesn't exist."   This could also be done with backslashes before the newlines, as mentioned in man bash:  If a \&lt;newline&gt; pair appears,  and  the  backslash  is  not itself  quoted,  the \&lt;newline&gt; is treated as a line continuation (that is, it is removed from the input stream and effectively ignored).   Example:  [ -f file1 ] &amp;&amp; \ [ -f file2 ] &amp;&amp; \ echo "Both files exist." || \ echo "One or the other file doesn't exist."   ...but this doesn't seem to be necessary.  The first version above works even without the backslashes.  Where can I find this in man bash?  (Also, is this bash specific or POSIX compliant?)
7069
Using a common command line tool like sed or awk, is it possible to join all lines that end with a given character, like a backslash?  For example, given the file:  foo bar \ bash \ baz dude \ happy   I would like to get this output:  foo bar bash baz dude happy
64797
Situation: It started out as me  for the literal string C-c in  but it ended up omitting the - sign and showing results which contained the strings C/C++ and C &amp; C++.  is an example of a post which contains that string of characters (yet fails to show up in the results).  Things I've tried:   post suggests that I can use the undocumented code: operator, but when I do that, it just wraps the whole term in double quotes like .  As @terdon in Unix &amp; Linux chat has , using this  does yield some relevant results, but it doesn't show me  that is supposed to be there. edit: It appears that the Symbolhound query no longer returns that result.  Finally,  says that you can search for literal characters, but as you can see:    Quoted phrases are exact matches except for case-sensitivity, for example, you can search  or .  The second example (symbols) leads to 0 results.  So by now I assume that the search engine has changed (but the old documentation still lingers on this site). Is there a method for me to search for strings that include special (or is it literal?) characters?
70098
I'm trying to get a regex that will match:  somefile_1.txt somefile_2.txt somefile_{anything}.txt   but not match:  somefile_16.txt   I tried  somefile_[^(16)].txt   with no luck (it includes even the "16" record)
87705
I have a file with a number of lines in a file filename.  I want to count how many lines start with character 'a', with 'b' and so on in one go.  What command i should execute.?
13068
Given a file like this:  1,768,12,46576457,7898 1,123,435,134,146 2,345,6756856,12312,1311 5,234,567465,12341,1341 1,3245,4356345,2442,13 9,423,2342,121,463 9,989,342,121,1212   I would like to list all rows (in bash terminal) such that the value in column 1 appears at least twice (in column 1). The result should be  1,768,12,46576457,7898 1,123,435,134,146 1,3245,4356345,2442,13 9,423,2342,121,463 9,989,342,121,1212
42108
I have a directory (e.g., abc/def/efg) with many sub-directories (e.g.,: abc/def/efg/(1..300)). All of these sub-directories have a common file (e.g., file.txt). I want to search a string only in this file.txt excluding other files. How can I do this?  I used  grep -arin "pattern" *, but it is very slow if we have many sub-directories and files.
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.
113861
I have 2 text files. Lets name them file1.txt and file2.txt  file1.txt is as follows  chr10   181144  225933 chr10   181243  225933 chr10   181500  225933 chr10   226069  255828 chr10   255989  267134 chr10   255989  282777 chr10   267297  282777 chr10   282856  283524 chr10   283618  285377 chr10   285466  285995   file2.txt is as follows  chr10   181144  225933 chr10   181243  225933 chr10   181500  225933 chr10   255989  282777 chr10   267297  282777 chr10   282856  283524 chr10   375542  387138 chr10   386930  387138 chr10   387270  390748 chr10   390859  390938 chr10   391051  394580 chr10   394703  395270   What I want to output in a single file is    All the common lines between file1 and file2 All the lines which are in file1 but are not common to both All the lines which are in file2 but are not common to both.   I wrote a Perl script to do this but I am pretty sure there must be a command line or an easier way to do it.