Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filename containing " causing grief with script 1

Status
Not open for further replies.

BJZeak

Programmer
May 3, 2008
230
CA
Basically there is a malformed 3rd party AIX process generating widow orphan files in a sensitive folder ... this has been ongoing for too long and needs to be cleaned up and kept clean until the real issue is resolved.

There are almost 6K files accumulated and continue to accumulate. I used the following script to attempt to clean up this mess but have run into another issue.

ls | grep blah > blah.txt

cat blah.txt | xargs -i mv "{}" archive/

the problem is this doesn't work because some of the filenames contain a '"' ... so I changed the script to

cat blah.txt | xargs -i mv `{}` archive/

no change

so I manually edited the blah.txt file and added a '\' in front of all the '"' entries and ran the script (without the ls) which did work

Is there a way to get around this problem without having to manually edit the list file?
 
What about this to save editing the file directly, sed replacing all " with \":-

ls | grep blah | sed 's/\"/\\\"/g' > blah.txt

cat blah.txt | xargs -i mv "{}" archive/
 
I like to use ksh arrays for something like this:

Code:
set -A files $(ls)
rm ${files[17]} #removes the 18th file in the array (starts counting at zero)
 
You can escape the " character in your scripts if you are going against them specifically. Or use a narrow or wide wild card character.

rm this\"andthat

rm this?andthat

rm this*that

Good luck
 
Thanx for all the responces ... the sed option worked great.
 
If it worked great, it would be equally great to give a star as recognition.

The internet - allowing those who don't know what they're talking about to have their say.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top