To use a file as input for program, the < operator can be used.

For example,

xmacroplay "$DISPLAY" < input.txt

However, is there a command to specify if I don't want to use the whole file, but only take some lines as input?

Some like,

xmacroplay "$DISPLAY" < input.txt --starting_line=100 --ending_line=120

(This surely won't work, just want to know if there are option like that)


Use sed or another tool to filter out the specific line and pipe it to the command. For example, the following will send only the 10th and 13th lines of the file to xmacroplay:

sed -n '10p; 13p' input.txt | xmacroplay "$DISPLAY" --starting_line=100 --ending_line=120

Or in awk:

awk 'NR == 10 || NR == 13' input.txt | xmacroplay "$DISPLAY" --starting_line=100 --ending_line=120

If, for some reason, you cannot use a pipe, use process substitution:

xmacroplay "$DISPLAY" --starting_line=100 --ending_line=120 < <(sed -n '10p; 13p' input.txt)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.