Folder name with spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Folder name with spaces
# 1  
Old 02-17-2011
Folder name with spaces

Hello,
When I give:
Code:
rm -f /usr/local/tomcat/temp_img/\Images\ for\ UAT/0918-721-163-001-4C-P_04.jpg

, the file is being deleted.

I am trying to do the same in a script as follows:

Step 1:
A file named del.txt will have the following (list of files to be deleted):
Code:
/usr/local/tomcat/temp_img/\Images\ for\ UAT/0918-721-163-001-4C-P_04.jpg

Step 2: The script
Code:
for fname in `cat del.txt`
do
        rm -f echo $fname
done

As I pass the line from del.txt in a FOR loop, the fname is set to following:
1. /usr/local/tomcat/temp_img/\Images\
2. for\
3. UAT/0918-721-163-001-4C-P_03.jpg

Hence the file is not being deleted. I tried the rm command within quotes
Code:
'rm -f echo $fname'
`rm -f echo $fname`
"rm -f echo $fname"

and also tried to put the test in del.txt within quotes. But no luck. Please help me.

Thanks,
risshanth

Last edited by Franklin52; 02-21-2011 at 03:02 AM.. Reason: Please use code tags, thank you
# 2  
Old 02-17-2011
Code:
while read fname
do
 rm -f echo "$fname"
done < del.txt

# 3  
Old 02-17-2011
Thank you so much !!!!!!
# 4  
Old 02-17-2011
Quote:
Originally Posted by vgersh99
Code:
while read fname
do
 rm -f echo "$fname"
done < del.txt

Smilie And the spaces won't need to be escaped in the del.txt file.
# 5  
Old 02-17-2011
Surely it's:
Code:
rm -f "$fname"

Andrew
# 6  
Old 02-17-2011
Quote:
Originally Posted by apmcd47
Surely it's:
Code:
rm -f "$fname"

Andrew
I guess that echo was left over from testing.

But rm -f won't complain about it.
# 7  
Old 02-21-2011
I did the testing after removing the escape char from del.txt
And, the echo was from my testing only

Thank you guys
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

3. Shell Programming and Scripting

Shell Script to Enter a Directory (Folder Name Contains Spaces)

I am writing a shell script to cd to a folder. folder name is "October Scripts" I am currently storing the name of folder in a shell variable as so path="October\ Scripts/". If I do cd $path I receive the error bash: cd: October\: No such file or directory What am I doing wrong? Kindly... (3 Replies)
Discussion started by: anand2308
3 Replies

4. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

5. Shell Programming and Scripting

File Management: How do I move all JPGS in a folder structure to a single folder?

This is the file structure: DESKTOP/Root of Photo Folders/Folder1qweqwasdfsd/*jpg DESKTOP/Root of Photo Folders/Folder2asdasdasd/*jpg DESKTOP/Root of Photo Folders/Folder3asdadfhgasdf/*jpg DESKTOP/Root of Photo Folders/Folder4qwetwdfsdfg/*jpg DESKTOP/Root of Photo... (4 Replies)
Discussion started by: guptaxpn
4 Replies

6. Windows & DOS: Issues & Discussions

How can I upload a zip folder on a unix path from my windows folder?

Hello, I am an amature at UNIX commands and functionality. Please could you all assist me by replying to my below mentioned querry : How can I upload a zip folder on a unix path from my windows folder? Thanks guys Cheers (2 Replies)
Discussion started by: ajit.yadav83
2 Replies

7. UNIX for Dummies Questions & Answers

how to append spaces(say 10 spaces) at the end of each line based on the length of th

Hi, I have a problem where I need to append few spaces(say 10 spaces) for each line in a file whose length is say(100 chars) and others leave as it is. I tried to find the length of each line and then if the length is say 100 chars then tried to write those lines into another file and use a sed... (17 Replies)
Discussion started by: prathima
17 Replies

8. UNIX for Advanced & Expert Users

Auto copy for files from folder to folder upon instant writing

Hello all, I'm trying to accomplish that if a file gets written to folder /path/to/a/ it gets automatically copied into /path/to/b/ the moment its get written. I thought of writing a shell script and cron it that every X amount of minutes it copies these files over but this will not help me... (2 Replies)
Discussion started by: Bashar
2 Replies

9. Shell Programming and Scripting

Parse the .txt file for folder name and FTP to the corrsponding folder.

Oracle procedure create files on UNIX folder on a regular basis. I need to FTP files onto windows server and place the files, based on their name, in the corresponding folders. File name is as follows: ccyymmddfoldernamefile.txt; Folder Name length could be of any size; however, the prefix and... (3 Replies)
Discussion started by: MeganP
3 Replies

10. Shell Programming and Scripting

Strip leading and trailing spaces only in a shell variable with embedded spaces

I am trying to strip all leading and trailing spaces of a shell variable using either awk or sed or any other utility, however unscuccessful and need your help. echo $SH_VAR | command_line Syntax. The SH_VAR contains embedded spaces which needs to be preserved. I need only for the leading and... (6 Replies)
Discussion started by: jerardfjay
6 Replies
Login or Register to Ask a Question