Hi I have a large number of files in a folder four example names are below.
This is a really long file name for a test 001.csv
This is a really long file name for a test 002.csv
This is a really long file name for a test 003.csv
This is a really long file name for a test 004.csv
I wanted to copy all the files in the current folder via ftp and rename them all to just the 001.csv 002.csv etc however if I do for files in `ls` the files names are split on the spaces in the names so $ file reads
this
is
a
really etc.
The solution I found was to do a string replace on the ls first using sed, which works, and then switch it back in the for loop but I'm just curious if there is a better solution to this.
This is the code I have:
Code:
#!/bin/bash
#copy files to the remote pc
for file in `ls *.csv | sed 's/ /~/g' `
do
file1=`echo $file | sed 's/~/ /g'`
file2=`echo $file1 | cut -c 44-`
echo "copying file $file2"
curl -T "$file1" -u uname:passwd ftp://192.168.5.230/"$file2"
done
so is it possible to not use sed ?