To give STDIN for Sed?
Basically you can do something like

eval $(echo sed $(for i in 1 2 3 5; do echo "-e ${i}p"; done) -n data.txt )




To read the line numbers from a file containing the numbers, separated by space, use

eval $(echo sed $(for i in $(&lt; line-numbers.txt); do echo "-e ${i}p"; done) -n data.txt )


In this case, you can use any command which produces a list of line number instead of the &lt; line-numbers.txt part.



Or, if the numbers in the file are separated by ,

eval $(echo sed $(for i in $(tr \, ' ' &lt; line-numbers.txt); do echo "-e ${i}p"; done) -n data.txt )


(and again, the command can be anything producing line numbers separated by ,)