Imagine having these two files:
First:
# foo
http://some.url/
# bar
http://foo.url/
# bar
http://and.one.more/url
Second:
foo
doo
Now, I want to print out from the First file those lines that start with #
and contain words from the Second file -- and not only these lines but also those urls that follow matched lines.
At first, it seemed I could use grep
:
grep -f Second -A 1 First
But, of course, that was a mistake:
# foo
http://some.url/
--
http://foo.url/
# bar
So, my question is, how can I limit filtering only to those lines that start with #
? And upon finding such lines, print those out, as well as the next line after those. Would be great if that could be done with some standard tools, like grep
, sed
, or awk
.
Desired outcome for this very example would be:
# foo
http://some.url/
EDIT: Sorry for disturbing you all, for my particular case I decided simply to join lines temporarily, then to grep -f Second First
, and then to split the resulting lines back on printing out.