Problem renaming a file with single quotes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem renaming a file with single quotes
# 1  
Old 09-15-2009
Problem renaming a file with single quotes

Hi,

I am trying to create a script which validates the incoming source files. The script has File name Pattern as Argument. The First part of the script validates if there are any files available

if [ -f $FILE_NAME ]
then
echo "\n Files are available to process \n"
else
echo "\n File does not exist: Process is Terminating \n"
exit 1
fi

I am receiving multiple files in the below format

'abc.def.ghi.jkl'
'abc.def.xty.xyz'
'abc.def.rew.ter'

I want to rename each of these files with out the single quotes as below

abc.def.ghi.jkl
abc.def.xty.xyz
abc.def.rew.ter

I am trying to do that using below code

for FILE_NAME in $FILE_NAME
do
mv "'$FILE_NAME'" "$FILE_NAME"

The Problem is when i am pass the argument with single quotes the mv command throws error.

I want to achieve 2 things
1.pass the argument(Filename) without the Single quotes by changing the internal code
2.Rename the files without the single quotes.

Please help.

Thanks,
# 2  
Old 09-15-2009
Try this:

Code:
cd /working_directory
for filename in `ls`
do
   new_filename=`echo $filename| tr "'" " "` 
   mv $filename $new_filename
done

# 3  
Old 09-15-2009
Or this:
Code:
for fn in *; do
  mv $fn ${fn//\'/}
done

or

Code:
for fn in *; do
  eval mv \$fn $fn
done

or perhaps more appropriate in this case Smilie
Code:
for fn in *; do
  eval mv '$fn' $fn
done


Last edited by Scrutinizer; 09-15-2009 at 05:19 PM..
# 4  
Old 09-15-2009
Its giving the below error

Usage: mv [-I] [-i | -f] [-E{force|ignore|warn}] [--] src target
or: mv [-I] [-i | -f] [-E{force|ignore|warn}] [--] src1 ... srcN directory
# 5  
Old 09-15-2009
Does this work?
Code:
for fn in \'*\'; do
  mv $fn ${fn//\'/}
done

or

Code:
for fn in \'*\'; do
  eval mv \$fn $fn
done

or

Code:
for fn in \'*\'; do
  eval mv '$fn' $fn
done

# 6  
Old 09-15-2009
all the three codes still want me to give the file name with single quotes as an argument ......is there anyway that i can do it with out giving the single quotes in the argument
# 7  
Old 09-15-2009
Code:
# for file in *\'*\'*;do echo mv "$file" "${file//\'/}";done
mv my'.'file my.file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with Single Quotes and Double Quotes for prompt PS1

Hi, Trying to change the prompt. I have the following code. export PS1=' <${USER}@`hostname -s`>$ ' The hostname is not displayed <abc@`hostname -s`>$ uname -a AIX xyz 1 6 00F736154C00 <adcwl4h@`hostname -s`>$ If I use double quotes, then the hostname is printed properly but... (3 Replies)
Discussion started by: bobbygsk
3 Replies

2. Shell Programming and Scripting

Having a terrible problem with quotes/single quotes!

Hello. I'm trying to write a bash script that uses GNU screen and have hit a brick wall that has cost me many hours... (I'm sure it has something to do with quoting/globbing, which is why I post it here) I can make a script that does the following just fine: test.sh: #!/bin/bash # make... (2 Replies)
Discussion started by: jondecker76
2 Replies

3. Shell Programming and Scripting

Search replace strings between single quotes in a text file

Hi There... I need to serach and replace a strings in a text file. My file has; books.amazon='Let me read' and the output needed is books.amazon=NONFOUND pls if anybody know this can be done in script sed or awk.. i have a list of different strings to be repced by NONFOUND.... (7 Replies)
Discussion started by: Hiano
7 Replies

4. Shell Programming and Scripting

File renaming problem

Can someone tell me how can i remove the RPCFTP word from RPCFTPfilelist.csv file ? (4 Replies)
Discussion started by: JSKOBS
4 Replies

5. Shell Programming and Scripting

Replace single quote with two single quotes in perl

Hi I want to replace single quote with two single quotes in a perl string. If the string is <It's Simpson's book> It should become <It''s Simpson''s book> (3 Replies)
Discussion started by: DushyantG
3 Replies

6. UNIX for Dummies Questions & Answers

grep single quotes or double quotes

Unix superusers, I am new to unix but would like to learn more about grep. I am very familiar with regular expressions as i have used them for searching text files in windows based text editors. Since I am not very familiar with Unix, I dont understand when one should use GREP with the... (2 Replies)
Discussion started by: george_vandelet
2 Replies

7. Shell Programming and Scripting

problem with echo inserting single quotes

Consider the following script: #!/bin/bash exclude='Archive PST,SystemState' IFS=$"," rsyncExclusions=$(for exclude in ${exclude}; do echo -n -e --exclude=\"${exclude}\"\ ; done) unset IFS echo rsync $rsyncExclusions test rsync -avh --delete --delete-excluded "$rsyncExclusions"... (7 Replies)
Discussion started by: jelloir
7 Replies

8. Shell Programming and Scripting

Single quotes and double quotes

Hi guys, I have a sed line in double quotes which works fine, but I want it to be in single quotes here is the sed line sed "/abc_def/s/\'.*\'/\'\${abc_def}\'/" can some one give the equivalent to the above script in single quotes Thanks a ton (5 Replies)
Discussion started by: sol_nov
5 Replies

9. Shell Programming and Scripting

Double quotes or single quotes when using ssh?

I'm not very familiar with the ssh command. When I tried to set a variable and then echo its value on a remote machine via ssh, I found a problem. For example, $ ITSME=itsme $ ssh xxx.xxxx.xxx.xxx "ITSME=itsyou; echo $ITSME" itsme $ ssh xxx.xxxx.xxx.xxx 'ITSME=itsyou; echo $ITSME' itsyou $... (3 Replies)
Discussion started by: password636
3 Replies

10. Shell Programming and Scripting

problem with single quotes in a string and findbug

I'm having trouble manipulating a string that contains single quotes (') in it. I'm writing a ksh script to parse in a few queries from a config file, such as this: findbug \(\(Project 'in' "Deployment,HDRCI,LHS,LSS,WUCI" '&&' Status 'in' "N" '&&' New_on 'lessthan' "070107" \)\) '&&' \(Class... (9 Replies)
Discussion started by: bob122480
9 Replies
Login or Register to Ask a Question