I want to grep some line from a log file with an input from another file. I'm using this small command to do that:
while read line; do
grep "$line" service.log;
done < input_strings.txt > result.txt
input_strings.txt
has like 50 000 strings (one per line). For every of this string I'm currently searching the huge service.log
file (with around 2 000 000 lines).
So lets say the 1st string of input_strings.txt
is found in service.log
at line 10 000, this line gets written to my result.txt
. After that, the 2nd string of input_strings.txt
will be searched in service.log
, BUT starting at line 1 of service.log
.
How can I remember the last line I found the 1st entry in service.log
? So that I can start the 2nd search-run there?
input_strings.txt
– RomanPerekhrest Dec 19 '17 at 10:06I just want to get the last position of a matched line, so i can start at this point for the next run of my while loop.
– xMaNuu Dec 19 '17 at 10:14grep
by itself can look for matches in a particular order. – ilkkachu Dec 19 '17 at 10:25read -r
instead of plainread
approximately every time. – ilkkachu Dec 19 '17 at 10:47