Shell – Reading lines from a file based on a list of line numbers and writing output to a utility

pipeshell-scripttext processing

I have a file with a list of lines I want to read from another file. I want to output those lines to a utility (grep) that lets me read the entire line and pull information from it. The file with the lines looks like this:

cat input.txt
2088
2089
2095
2096

For some reason I am stuck on this. I know sed can take a specific line number as an argument, but I can't figure how to get this into a variable to feed to it.

Best Answer

awk 'NR==FNR{linesToPrint[$0];next}
     FNR in linesToPrint' line-numbers.txt file.txt
Related Question