Suppose I have two files named a.txt and b.txt. Is there any way to use all the contents of file a.txt to use as  patterns for grep command if I want to search in file b.txt?  General format of grep is:  grep 'pattern' 'filename'
40934
I have a couple of big text files and in the file UNIQS.txt I have a list of strings to grep from another file. The code I use is  grep -f UNIQS.txt EEP_VSL.uniqs.sam &gt; UNIQ_templates.sam   which does nothing - the file generated is empty. But when I do  grep -F -f UNIQS.txt EEP_VSL.uniqs.sam &gt; UNIQ_templates.sam   it works correctly. This confuses me because I didn't think grep would interpret the entries in UNIQS.txt as regexp patterns without quotes and slashes and so on being in the file (which there aren't). Is it the case in general that if you are getting the patterns from a file then it will automatically think that they are regexp patterns?  Edit: In the UNIQS.txt file, there are newline separated strings of the form  HWI-ST365:215:D0GH0ACXX:2:1101:10034:186783   (called template names) and the file EEP_VSL... tab separated columns, with about 14 columns and the first column is the template name, so basically I want to extract the line corresponding to each template in the file.
103962
I'm using grep in bash to search for the string "-1" .  I would usually search for "bar" like this ...  glaucon@foo $ grep -irn "bar"   ... which works fine but when I try to search for "-1" I get this ...  glaucon@foo $ grep -irn "-1" Usage: grep [OPTION]... PATTERN [FILE]... Try 'grep --help' for more information.   ... I thought the minus might be a special character but it appears not . I also tried using the 'fixed strings' option in case this was some aspect of regex I was unfamiliar with ...  glaucon@foo $ grep -irnF "-1" Usage: grep [OPTION]... PATTERN [FILE]... Try 'grep --help' for more information.   ... but, as shown, that doesn't provide output either.   I'm sure this is straightforward but ... how ?  Thanks
55783
I am trying to run grep against a list of a few hundred files:  $ head -n 3 &lt;(cat files.txt) admin.php ajax/accept.php ajax/add_note.php   However, even though I am grepping for a string that I know is found in the files, the following does not search the files:  $ grep -i 'foo' &lt;(cat files.txt)  $ grep -i 'foo' admin.php The foo was found   I am familiar with the -f flag which will read the patterns from a file. But how to read the input files?  I had considered the horrible workaround of copying the files to a temporary directory as cp seems to support the &lt;(cat files.txt) format, and from there grepping the files. Shirley there is a better way.
81623
I am writing a script, I want to check if the first line of the file matches a certain pattern and if it does then print out the file. How can I achieve this?  How do I check for pattern? Is there a way to check for pattern and based on the output do something..  EDIT: Please take a look at this question:   I want something like this, but none of them worked for me. I basically want to check if the first line matches a regex pattern or not and based on that print the lines of file.
46112
Say I'm printing out a long series of strings, and instead of only showing lines containing a certain pattern (which one uses "grep" to do), how do I filter out certain patterns?
85009
I have the following code that I run on my Terminal.  LC_ALL=C &amp;&amp; grep -F -f  genename2.txt hg38.hgnc.bed &gt; hg38.hgnc.goi.bed   This doesn't give me the common lines between the two files. What am I missing there?
63109
Using the top command with redirection works fine:  top &gt; top.log   Now I want to use grep to filter a certain line:  top | grep "my_program" &gt; top.log   But the log file will remain empty. But grep delivers an output when using  top | grep "my_program"   Where my_program has to be replaced by a running program to see some output.  Why does my approach not work ? And how can I fix it ?
85028
Comparing     grep '.*[s]' file   with     grep .*[s] file   Why do you need quotation marks to let this work properly? In the second case, grep seems trying to inspect every file with a period.
75528
More often that I like to admit I look for a file that contains some strings.  Currently I do:  grep -rl string1 | xargs grep -l string2 | xargs grep -l string3   Is there a tool that does this prettier?  This greps for string1 or string2 or string3.   grep -rl -e string1 -e string2 -e string3   I want files that contain string1 and string2 and string3 but not necessarily on the same line.  Maybe one of the modern greps (ag/ack/rg/sift) can do this?
87030
I am doing grep and sed and I get 2 lines of a file that I am interested in. How can I get these lines in a single line ending with the new line character? Now I am getting:    pattern1   pattern2     I would like to get pattern1 pattern2 \n
19564
I am using Solaris 10 and so grep options involving -f don't work.  I have two pipe-separated files:   file1:  abc|123|BNY|apple| cab|234|cyx|orange| def|kumar|pki|bird|   file 2:   abc|123| kumar|pki| cab|234   I would like to compare the first two columns of file2 with file1 (search through the entire contents of file1 in first two columns) if they match print the matched line of file1. Then search for the second line of file 2 and so on.   Expected Output:  abc|123|BNY|apple| cab|234|cyx|orange|   The files I have are huge, containing about 400,000 lines, so I would like to make the execution fast.
40827
I use the grep command to search for a string in many files. Is there something similar to "search and replace"?
60609
My data is like:   First_file.txt  Start abcd efgh hijk lmn  Second_File.txt  opq rst uvw xyz END      I want to grep all the line between patterns START &amp; END even END pattern in next file  Output should be like:  abcd efgh hijk lmn opq rst uvw xyz
13336
grep returns just the line where it matched the regex and often what I want to really see is a few (say 2) lines above and below the matched one. Is there a simple way to achieve it?  EDIT: OS: Ubuntu based Bodhi Linux.  As mentioned in comments, -C does not work in vanilla but its GNU grep in my case.
97947
I’m taking two input files, one with certain ID numbers, and another with a large list of ID numbers and additional columns. The latter file contains multiple lines for each ID number and I need to extract all lines that match an ID from the first file. Those lines then must be printed in a new file.  Edit 1: Replaced sample files with excerpts from actual  Edit 2: Removed extra spaces that were in excerpt, but not actual file. Files likely need to be sanitized in some way, but how is unclear.  file1:  AT1G56430 AT3G55190 AT3G22880   file2:  AT1G01010|GO:0043090|RCA AT1G56430|GO:0010233|IGI  AT1G56430|GO:0009555|IGI  AT1G56430|GO:0030418|IGI   expected output  AT1G56430|GO:0010233|IGI  AT1G56430|GO:0009555|IGI  AT1G56430|GO:0030418|IGI   [[  I have tried:  awk -F'|' 'NR==FNR{c[$1$2]++;next};c[$1$2] &gt; 0' file1 file2 &gt; output.txt   and:  grep -Ff file2 file1 &gt; output.txt   I’m aware that there are many somewhat similar questions posted in these forums and others. However, these don’t mention how the output is handled… nor do they mention duplicates. I’ve tried solutions from 4 of them, have been messing with this for many hours and keep getting the same problem: a blank output file.   I’m new to awk and I greatly appreciate the help. Sorry if this is a simple problem with syntax etc; please let me know. Thanks for the help.
66091
I'm trying to use grep to show only lines containing either of the two words, if only one of them appears in the line, but not if they are in the same line.  So far I've tried  grep pattern1 | grep pattern2 | ... but didn't get the result I expected.
5499
I often want to search through a man page, however I am forced to either do:  man &lt;package&gt; | grep &lt;search&gt;   Or:  man &lt;package&gt; &gt; file.txt   But there must be an easier way than this to do this, so how can I search through a man page while in it instead of having to send its contents to a file, or use grep to print the necessary matching contents to standard output?