tags:

views:

59

answers:

3

How do I pass each line from a text file as an argument to a script I have written? So each line is then in itself a single arg to the script each time.

+3  A: 
cat file | xargs --replace script {}

I should note that if you want each line of the file to be treated as one argument to your script, add quotes as appropriate to the {}, most likely \"{}\"

frankc
Wrong, {} will be substituted as one argument regardless of contents. What you want is to change the delimiter from any space (default) to newlines-only, using `-d '\n'` or similar.
ephemient
+1  A: 

you can do this

while read -r line
do
  ./script_i_have_written.sh "$line"
done <"file"

but why do that when in your "script_i_have_written.sh", you can parse the text file straight away

#!/bin/bash
# script_i_have_written.sh
while read -r line
do 
  echo "do something with $line"
done <"file"
ghostdog74
+2  A: 

No need for cat

xargs -I {} --arg-file input-file script_file {}
Dennis Williamson