I know this is a couple of days old, but I'm not sure the shell loops are necessary, as the sed command can read through the whole file on its own, before using something like xargs to combine all the files into a single mv command:
prev_dir=/cygdrive/c/Users/abhisek.samanta/Desktop/Table_scripts
new_dir=/cygdrive/c/Users/abhisek.samanta/Desktop/New
cd ${prev_dir}
sed 's/\r$//' filelist | xargs mv -t $new
Here, using the given directories, and the sed
command you have found works, then as everything is piped into xargs
, it will add each line from the pipe onto the mv
command, which can take multiple files and then move them all to the directory given with the -t
flag
$ > cat movefile.sh
new="$(pwd)/dir1/"
sed 's/\r$//' filelist | xargs mv -t $new
$ > cat -v filelist
file1^M
file2^M
file3^M
$ > touch file{1,2,3}
$ > ls -l
total 16
drwxr-xr-x 2 grownups users 4096 Jan 1 22:29 dir1
-rw-r--r-- 1 grownups users 0 Jan 1 22:30 file1
-rw-r--r-- 1 grownups users 0 Jan 1 22:30 file2
-rw-r--r-- 1 grownups users 0 Jan 1 22:30 file3
-rw-r--r-- 1 grownups users 22 Jan 1 22:26 filelist
-rwxr--r-- 1 grownups users 61 Jan 1 22:29 movefile.sh
$ > ls dir1/
$ > ./movefile.sh
$ > ls -l dir1/
total 0
-rw-r--r-- 1 grownups users 0 Jan 1 22:30 file1
-rw-r--r-- 1 grownups users 0 Jan 1 22:30 file2
-rw-r--r-- 1 grownups users 0 Jan 1 22:30 file3
$ >
tr
installed? It should be. If so, you can dotr -d '\r' < req_files.txt > no_dos_list.txt
to remove the dos line returns. The next question is, do you have files with a space in their name?req_files.txt
file