Quote (^thehatsrule^ @ Jan. 30 2007,16:09) |
If you plan on using sed, you could use "s/ /\ /g" If you plan on using a shell script, you could use IFS (i.e. IFS=" " or use 'read') Or you could just remember to never use spaces in filenames :P |
Quote |
read [-ers] [-u fd] [-t timeout] [-a aname] [-p prompt] [-n nchars] [-d delim] [name ...] One line is read from the standard input, or from the file descriptor fd supplied as an argument to the -u option, and the first word is assigned to the first name, the second word to the second name, and so on, with leftover words and their intervening separators assigned to the last name. If there are fewer words read from the input stream than names, the remain- ing names are assigned empty values. The characters in IFS are used to split the line into words. The backslash character (\) may be used to remove any special meaning for the next charac- ter read and for line continuation. |
Code Sample |
IFS=`echo -e "\n"` && cat `echo -e "one two three\nfour five six\nseven" | sed -e 's/ /\\ /g'` |
Quote |
cat: one two three four five six seven: No such file or directory |
Quote |
cat: one two three: No such file or directory cat: four five six: No such file or directory cat: seven: No such file or directory |
Code Sample |
# 1st make sure file ends in a newline sed -i '$ s/$/\n/' list.txt; while read LINE; do # set single quotes around each filename to be safe LN=\'"${LINE}"\' echo "${LN}" | xargs cat done <"list.txt" |