I am trying to write a script that will copy all file listed in a text file (100s of file names) to a new directory each time I run it
Essentially i wanna pick out certain files from a large collection to form a smaller on
Im trying to work up a test script using this scaled down model
Assume the script will run with main as current working directory and I know how many files/lines will be in List.txt
Contents of main
script.sh
sort < is a folder
List.txt
stuff.pdf
misc.rtf
junk.txt
thing.txt
Contents of List.txt
stuff.pdf
misc.rtf
thing.txt
Script so far (contests of script.sh)
#1/bin/bash
count =0
while [ $count -le 3 ]
do
filename= sed -n '1p' List
cp $filename sort
count=$(($count + 1 ))
done
Problems
(1)
count though lines with counter
something like
filename= sed -n '$countp' List
Im open to useing a different command here cat or whatever
but I want it to take the value from $count and grab whatevers is on the coresponding line in List.txt and store the result in a variable
(2)
use the file name stored in $filename in copy command
currenty gives error "cp: missing destination file operand after 'sort'"
I know this means its not reading the file name from $filename and is using sort as target not the destination but I dunno how to fix.
Any help would be appreciated :)
Essentially i wanna pick out certain files from a large collection to form a smaller on
Im trying to work up a test script using this scaled down model
Assume the script will run with main as current working directory and I know how many files/lines will be in List.txt
Contents of main
script.sh
sort < is a folder
List.txt
stuff.pdf
misc.rtf
junk.txt
thing.txt
Contents of List.txt
stuff.pdf
misc.rtf
thing.txt
Script so far (contests of script.sh)
#1/bin/bash
count =0
while [ $count -le 3 ]
do
filename= sed -n '1p' List
cp $filename sort
count=$(($count + 1 ))
done
Problems
(1)
count though lines with counter
something like
filename= sed -n '$countp' List
Im open to useing a different command here cat or whatever
but I want it to take the value from $count and grab whatevers is on the coresponding line in List.txt and store the result in a variable
(2)
use the file name stored in $filename in copy command
currenty gives error "cp: missing destination file operand after 'sort'"
I know this means its not reading the file name from $filename and is using sort as target not the destination but I dunno how to fix.
Any help would be appreciated :)