I have a file A with 400,000 lines. I have another file B that has a bunch of line numbers.
File B:
-------
98
101
25012
10098
23489
I have to extract those line numbers specified in file B from file A. That is I want to extract lines 98,101,25012,10098,23489 from file A. How to extract these lines in the following cases.
- File B is a explicit file.
- File B is arriving out of a pipe. For eg., grep -n pattern somefile.txt is giving me the file B.
I wanted to use see -n 'x'p fileA. However, I don't know how to give the 'x' from a file. Also, I don't to how to pipe the value of 'x' from a command.
awk fits this task better:
fileA in file case:
fileA content from pipe:
oh, you want FileB in file or from pipe, then same awk cmd:
and
sed
can print the line numbers you want:If you want multiple lines:
To transform a set of lines to a
sed
command like this, usesed
for beautifulsed
ception:Putting it all together:
Testing:
QED.