Hi, this is my first post and hope to make some contribution soon.
I'm still learning the basics of UNIX and Linux and BASH. Thus my need to understand the subject at hand. I don't have a problem with technical detail, so hit me
I have a script where two commands use the contents of a text file (containing path and file names) to perform actions on those files.
My question is this:
One of the commands needs to have the equals-signs and commas escaped (in the file names) but the other command doesn't. Why is this?
Thanks in advance.
Script file in progress:
#Move a limited number of files including their folder structure
find ./ -type f -print | head -n 500 > listoffiles.txt
This next command does NOT need to have the commas and equals signs escaped
# (this command doesn't need to have the equals and commas escaped
cat listoffiles.txt | cpio -pdm /app/facts/sm/ftp/utran_rbs/
# Find and replace text in files
# replace comma and equals sign , = with \, and \= we have to escape the escape sign so \, becomes \\, and \= becomes \\=
find . -name 'listoffiles.txt' | xargs perl -pi -e 's/=/\\=/g'
find . -name 'listoffiles.txt' | xargs perl -pi -e 's/,/\\,/g'
This next command DOES need to have the commas and equals signs escaped
# Remove the files after they have been copied (maybe I need some kind of automated check here. At the moment I do a manual count of the files in the target folder to see if the files were copied
# (this command does need to have the equals and commas escaped
cat listoffiles.txt | xargs /bin/rm -f
small extract of some of the file names contained in listoffiles.txt:
before change:
./SubNetwork=RBRNC1/MeContext=U0004-Nedbank_Gardens/A20101015.0945+0200-1000+0200_SubNetwork=ONRM_RootMo,SubNetwork=RBRNC1,MeContext=U0004-Nedbank_Gardens_statsfile.xml
./SubNetwork=RBRNC1/MeContext=U7147-Victory_Park_CC/A20101015.0945+0200-1000+0200_SubNetwork=ONRM_RootMo,SubNetwork=RBRNC1,MeContext=U7147-Victory_Park_CC_statsfile.xml
After Change:
./SubNetwork\=RBRNC1/MeContext\=U0004-Nedbank_Gardens/A20101015.0945+0200-1000+0200_SubNetwork\=ONRM_RootMo\,SubNetwork\=RBRNC1\,MeContext\=U0004-Nedbank_Gardens_statsfile.xml
./SubNetwork\=RBRNC1/MeContext\=U7147-Victory_Park_CC/A20101015.0945+0200-1000+0200_SubNetwork\=ONRM_RootMo\,SubNetwork\=RBRNC1\,MeContext\=U7147-Victory_Park_CC_statsfile.xml
P.S. I'm trying to develop a script, so if anyone has suggestions for improvement, they will be very welcome. Alternatively I can post this as a separate thread for clarity's sake.
The script is intended to:
1) take a folder (A) with a very large number of files and subfolders and move the files to another folder (B) while keeping the folder structure.
2) The subfolders might exist in the target folder, so mv did seem to like that
3) Move a specific number of files at a time so as not to overwhelm the processing of the files in the target folder.
4) Process the next source folder and repeat the process