hi all,<\/p>\n
im creating a script and i want it to do this -<\/p>\n
grep -Ril “text-to-find-here” /path-to-search<\/p>\n
but instead of “text-to-find-here” i want to put a file in here, in this file is a bunch of filenames, so -<\/p>\n
qwerty.txt<\/p>\n
asdfg.txt<\/p>\n
zxcvb.txt<\/p>\n
poiuy.txt<\/p>\n
and the list of file names goes on and on…<\/p>\n
and where \" /path-to-search \" is, is where the directory is that holds a bunch of files and in those files there are loads and loads of lines (as in a previous script i did a find files in a directory and got it to ouput it to a file.txt<\/p>\n
and if it finds any patterns i want it to ouput it to another file<\/p>\n
im struggling on this bit<\/p>\n
cheers,<\/p>\n
rob<\/p>","upvoteCount":2,"answerCount":5,"datePublished":"2018-06-05T18:37:39.000Z","author":{"@type":"Person","name":"robertkwild","url":"https://community.spiceworks.com/u/robertkwild"},"suggestedAnswer":[{"@type":"Answer","text":"
hi all,<\/p>\n
im creating a script and i want it to do this -<\/p>\n
grep -Ril “text-to-find-here” /path-to-search<\/p>\n
but instead of “text-to-find-here” i want to put a file in here, in this file is a bunch of filenames, so -<\/p>\n
qwerty.txt<\/p>\n
asdfg.txt<\/p>\n
zxcvb.txt<\/p>\n
poiuy.txt<\/p>\n
and the list of file names goes on and on…<\/p>\n
and where \" /path-to-search \" is, is where the directory is that holds a bunch of files and in those files there are loads and loads of lines (as in a previous script i did a find files in a directory and got it to ouput it to a file.txt<\/p>\n
and if it finds any patterns i want it to ouput it to another file<\/p>\n
im struggling on this bit<\/p>\n
cheers,<\/p>\n
rob<\/p>","upvoteCount":2,"datePublished":"2018-06-05T18:37:39.000Z","url":"https://community.spiceworks.com/t/grep-file-for-patterns-of-lines/655417/1","author":{"@type":"Person","name":"robertkwild","url":"https://community.spiceworks.com/u/robertkwild"}},{"@type":"Answer","text":"
think i have found it the -f option<\/p>","upvoteCount":1,"datePublished":"2018-06-05T18:46:02.000Z","url":"https://community.spiceworks.com/t/grep-file-for-patterns-of-lines/655417/2","author":{"@type":"Person","name":"robertkwild","url":"https://community.spiceworks.com/u/robertkwild"}},{"@type":"Answer","text":"
this is what my script looks like so far, gonna amend -<\/p>\n
#!/bin/bash<\/p>\n
echo “enter the path what holds all the files for directory listings”
\nread -e files<\/p>\n
echo “enter the file path what strings you want me to search for”
\nread -e search<\/p>\n
echo “enter the path where the results will be made”
\nread -e results<\/p>\n
echo “what do you want the results file to be called”
\nread file<\/p>\n
cd “$files”<\/p>\n
grep -rinf “$search” . >> “$results”/“$file”<\/p>","upvoteCount":0,"datePublished":"2018-06-05T20:12:35.000Z","url":"https://community.spiceworks.com/t/grep-file-for-patterns-of-lines/655417/3","author":{"@type":"Person","name":"robertkwild","url":"https://community.spiceworks.com/u/robertkwild"}},{"@type":"Answer","text":"
i have put the -w option in there aswell so its -rwinf<\/p>","upvoteCount":0,"datePublished":"2018-06-06T20:47:55.000Z","url":"https://community.spiceworks.com/t/grep-file-for-patterns-of-lines/655417/4","author":{"@type":"Person","name":"robertkwild","url":"https://community.spiceworks.com/u/robertkwild"}},{"@type":"Answer","text":"
You can also cat all the files and pipe the grep command like<\/p>\n
cat f1.txt f2.txt|grep {condition}<\/p>","upvoteCount":0,"datePublished":"2018-07-03T20:12:19.000Z","url":"https://community.spiceworks.com/t/grep-file-for-patterns-of-lines/655417/5","author":{"@type":"Person","name":"samitjain","url":"https://community.spiceworks.com/u/samitjain"}}]}}