#!/bin/bash
# does this help?
# Make a list of files to process:
# it is ls -"one" not -"el"
ls -1 >> list_of_files.txt
find /xxx/yyy -name *.txt >> list_of_files.txt
for file_name in `cat list_of_files.txt`
do
# process the file e.g.
[ ! -f $file_name ] && echo "$file_name does not exist. Check if it is absolute path or relative path. If it is relative path ensure you are running the script in correct directory."
echo cp $file_name some_dir
done
# if the list_of_files.txt is very big you can do this as well:
while read file_name
do
# process the file e.g.
[ ! -f $file_name ] && echo "$file_name does not exist. Check if it is absolute path or relative path. If it is relative path ensure you are running the script in correct directory."
echo cp $file_name some_dir
done < list_of_files.txt
PS:
ls and find (depending on arguments) return relative paths, so ensure that either your script is run in the correct directory. Or edit the list_of_files.txt to make all paths absolute.
E.g.
my_curr_dir=`pwd`
ls -1 . >> list_of_files.txt
echo "relative paths:"
cat list_of_files.txt
echo "absolute paths:"
sed "s/^/$(echo $my_curr_dir/ | sed 's/[/]/\\\//g')/" list_of_files.txt
# edit the file itself:
sed -i "s/^/$(echo $my_curr_dir/ | sed 's/[/]/\\\//g')/" list_of_files.txt
echo "absolute paths inside the file:"
cat list_of_files.txt thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75