grep; Obtaining patterns from a file, Ignoring case












0















I'm quite unfamiliar with Unix, and I am trying to understand how to perform grep through a list of text files, using patterns stored in a text file called searchlist.txt. The text file is a new-line separated list of names that looks something like this:




"washington, martha"



"adams, jane"




And I need to search for these names in some very large text files. I also need to ignore case. I've come up with grep -i -f searchlist.txt *.txt, but the only output I am getting looks like this:




"adams, jane":"washington, martha"




I know for certain that these names are somewhere in the text files. I wonder if there is some specific way that searchlist.txt needs to be formatted? Is there some way I need to specify in the command that this list is separated by new lines?










share|improve this question














bumped to the homepage by Community 14 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Does your text file include the double quote marks? If not, please remove them.

    – roaima
    Jan 11 '17 at 20:39











  • Did the file come from a Windows or Mac system? If so, please transfer it using text mode and try again. Or convert it from Windows/Mac format to Unix format.

    – roaima
    Jan 11 '17 at 20:39













  • These two fixes did the trick. Thank you very much!

    – user209924
    Jan 11 '17 at 20:47
















0















I'm quite unfamiliar with Unix, and I am trying to understand how to perform grep through a list of text files, using patterns stored in a text file called searchlist.txt. The text file is a new-line separated list of names that looks something like this:




"washington, martha"



"adams, jane"




And I need to search for these names in some very large text files. I also need to ignore case. I've come up with grep -i -f searchlist.txt *.txt, but the only output I am getting looks like this:




"adams, jane":"washington, martha"




I know for certain that these names are somewhere in the text files. I wonder if there is some specific way that searchlist.txt needs to be formatted? Is there some way I need to specify in the command that this list is separated by new lines?










share|improve this question














bumped to the homepage by Community 14 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Does your text file include the double quote marks? If not, please remove them.

    – roaima
    Jan 11 '17 at 20:39











  • Did the file come from a Windows or Mac system? If so, please transfer it using text mode and try again. Or convert it from Windows/Mac format to Unix format.

    – roaima
    Jan 11 '17 at 20:39













  • These two fixes did the trick. Thank you very much!

    – user209924
    Jan 11 '17 at 20:47














0












0








0








I'm quite unfamiliar with Unix, and I am trying to understand how to perform grep through a list of text files, using patterns stored in a text file called searchlist.txt. The text file is a new-line separated list of names that looks something like this:




"washington, martha"



"adams, jane"




And I need to search for these names in some very large text files. I also need to ignore case. I've come up with grep -i -f searchlist.txt *.txt, but the only output I am getting looks like this:




"adams, jane":"washington, martha"




I know for certain that these names are somewhere in the text files. I wonder if there is some specific way that searchlist.txt needs to be formatted? Is there some way I need to specify in the command that this list is separated by new lines?










share|improve this question














I'm quite unfamiliar with Unix, and I am trying to understand how to perform grep through a list of text files, using patterns stored in a text file called searchlist.txt. The text file is a new-line separated list of names that looks something like this:




"washington, martha"



"adams, jane"




And I need to search for these names in some very large text files. I also need to ignore case. I've come up with grep -i -f searchlist.txt *.txt, but the only output I am getting looks like this:




"adams, jane":"washington, martha"




I know for certain that these names are somewhere in the text files. I wonder if there is some specific way that searchlist.txt needs to be formatted? Is there some way I need to specify in the command that this list is separated by new lines?







grep






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 11 '17 at 20:38









user209924user209924

11




11





bumped to the homepage by Community 14 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 14 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Does your text file include the double quote marks? If not, please remove them.

    – roaima
    Jan 11 '17 at 20:39











  • Did the file come from a Windows or Mac system? If so, please transfer it using text mode and try again. Or convert it from Windows/Mac format to Unix format.

    – roaima
    Jan 11 '17 at 20:39













  • These two fixes did the trick. Thank you very much!

    – user209924
    Jan 11 '17 at 20:47



















  • Does your text file include the double quote marks? If not, please remove them.

    – roaima
    Jan 11 '17 at 20:39











  • Did the file come from a Windows or Mac system? If so, please transfer it using text mode and try again. Or convert it from Windows/Mac format to Unix format.

    – roaima
    Jan 11 '17 at 20:39













  • These two fixes did the trick. Thank you very much!

    – user209924
    Jan 11 '17 at 20:47

















Does your text file include the double quote marks? If not, please remove them.

– roaima
Jan 11 '17 at 20:39





Does your text file include the double quote marks? If not, please remove them.

– roaima
Jan 11 '17 at 20:39













Did the file come from a Windows or Mac system? If so, please transfer it using text mode and try again. Or convert it from Windows/Mac format to Unix format.

– roaima
Jan 11 '17 at 20:39







Did the file come from a Windows or Mac system? If so, please transfer it using text mode and try again. Or convert it from Windows/Mac format to Unix format.

– roaima
Jan 11 '17 at 20:39















These two fixes did the trick. Thank you very much!

– user209924
Jan 11 '17 at 20:47





These two fixes did the trick. Thank you very much!

– user209924
Jan 11 '17 at 20:47










1 Answer
1






active

oldest

votes


















0














If you have a file called 'needles' containing the following:



washington, martha
adams, jane


And a file called 'haystack' containing the following:



blah blah blah washington, martha blah
all work and no play
makes adams, jane a dull
girl


You should be able to use grep -i -f needles haystack.



If, however, 'needles' contains:



"washington, martha"
"adams, jane"


you will need to use grep -i -f <(sed 's/"//g' needles) haystack to strip the double-quotes off of the names. Unless, that is, you want to search for only the names when quoted.



Naturally, this will not work for cases of 'haystack' such as



And on that day she changed her name to adams,
jane.


If someone on your list is inspired by The Artist Formerly Known As The Artist Formerly Known As Prince and has decided to put a double-quote into their actual name, you can make the sed a little more explicit and only strip the leading and trailing quote from each line with grep -i -f <(sed 's/^"//;s/"$//' needles) haystack.






share|improve this answer


























  • This is great, thank you. In addition to stripping quotes, I'd needed to convert the text file to Unix format. Thanks again.

    – user209924
    Jan 11 '17 at 20:57











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f336676%2fgrep-obtaining-patterns-from-a-file-ignoring-case%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If you have a file called 'needles' containing the following:



washington, martha
adams, jane


And a file called 'haystack' containing the following:



blah blah blah washington, martha blah
all work and no play
makes adams, jane a dull
girl


You should be able to use grep -i -f needles haystack.



If, however, 'needles' contains:



"washington, martha"
"adams, jane"


you will need to use grep -i -f <(sed 's/"//g' needles) haystack to strip the double-quotes off of the names. Unless, that is, you want to search for only the names when quoted.



Naturally, this will not work for cases of 'haystack' such as



And on that day she changed her name to adams,
jane.


If someone on your list is inspired by The Artist Formerly Known As The Artist Formerly Known As Prince and has decided to put a double-quote into their actual name, you can make the sed a little more explicit and only strip the leading and trailing quote from each line with grep -i -f <(sed 's/^"//;s/"$//' needles) haystack.






share|improve this answer


























  • This is great, thank you. In addition to stripping quotes, I'd needed to convert the text file to Unix format. Thanks again.

    – user209924
    Jan 11 '17 at 20:57
















0














If you have a file called 'needles' containing the following:



washington, martha
adams, jane


And a file called 'haystack' containing the following:



blah blah blah washington, martha blah
all work and no play
makes adams, jane a dull
girl


You should be able to use grep -i -f needles haystack.



If, however, 'needles' contains:



"washington, martha"
"adams, jane"


you will need to use grep -i -f <(sed 's/"//g' needles) haystack to strip the double-quotes off of the names. Unless, that is, you want to search for only the names when quoted.



Naturally, this will not work for cases of 'haystack' such as



And on that day she changed her name to adams,
jane.


If someone on your list is inspired by The Artist Formerly Known As The Artist Formerly Known As Prince and has decided to put a double-quote into their actual name, you can make the sed a little more explicit and only strip the leading and trailing quote from each line with grep -i -f <(sed 's/^"//;s/"$//' needles) haystack.






share|improve this answer


























  • This is great, thank you. In addition to stripping quotes, I'd needed to convert the text file to Unix format. Thanks again.

    – user209924
    Jan 11 '17 at 20:57














0












0








0







If you have a file called 'needles' containing the following:



washington, martha
adams, jane


And a file called 'haystack' containing the following:



blah blah blah washington, martha blah
all work and no play
makes adams, jane a dull
girl


You should be able to use grep -i -f needles haystack.



If, however, 'needles' contains:



"washington, martha"
"adams, jane"


you will need to use grep -i -f <(sed 's/"//g' needles) haystack to strip the double-quotes off of the names. Unless, that is, you want to search for only the names when quoted.



Naturally, this will not work for cases of 'haystack' such as



And on that day she changed her name to adams,
jane.


If someone on your list is inspired by The Artist Formerly Known As The Artist Formerly Known As Prince and has decided to put a double-quote into their actual name, you can make the sed a little more explicit and only strip the leading and trailing quote from each line with grep -i -f <(sed 's/^"//;s/"$//' needles) haystack.






share|improve this answer















If you have a file called 'needles' containing the following:



washington, martha
adams, jane


And a file called 'haystack' containing the following:



blah blah blah washington, martha blah
all work and no play
makes adams, jane a dull
girl


You should be able to use grep -i -f needles haystack.



If, however, 'needles' contains:



"washington, martha"
"adams, jane"


you will need to use grep -i -f <(sed 's/"//g' needles) haystack to strip the double-quotes off of the names. Unless, that is, you want to search for only the names when quoted.



Naturally, this will not work for cases of 'haystack' such as



And on that day she changed her name to adams,
jane.


If someone on your list is inspired by The Artist Formerly Known As The Artist Formerly Known As Prince and has decided to put a double-quote into their actual name, you can make the sed a little more explicit and only strip the leading and trailing quote from each line with grep -i -f <(sed 's/^"//;s/"$//' needles) haystack.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 11 '17 at 20:47

























answered Jan 11 '17 at 20:41









DopeGhotiDopeGhoti

44.2k55683




44.2k55683













  • This is great, thank you. In addition to stripping quotes, I'd needed to convert the text file to Unix format. Thanks again.

    – user209924
    Jan 11 '17 at 20:57



















  • This is great, thank you. In addition to stripping quotes, I'd needed to convert the text file to Unix format. Thanks again.

    – user209924
    Jan 11 '17 at 20:57

















This is great, thank you. In addition to stripping quotes, I'd needed to convert the text file to Unix format. Thanks again.

– user209924
Jan 11 '17 at 20:57





This is great, thank you. In addition to stripping quotes, I'd needed to convert the text file to Unix format. Thanks again.

– user209924
Jan 11 '17 at 20:57


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f336676%2fgrep-obtaining-patterns-from-a-file-ignoring-case%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Loup dans la culture

How to solve the problem of ntp “Unable to contact time server” from KDE?

Connection limited (no internet access)