Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-08-2012, 02:29 AM
|
#1
|
Member
Registered: Jul 2012
Posts: 30
Rep: 
|
Move file names with space to other directory with different file name with space
Hi,
I want to move the files from one directory to another directory.
Condition i have is: file names are with spaces. Ex: "my file" , "your file".
I used the below command.
mv $current_dir/my\ file $remote_dir/their\ file
this moves "my file" to $remote_dir/ "their file"
But the problem im facing is i ll not beknowint the name of the file. File name will be stored in a variable.
So when i used variable, the space in the file name is creating problem.
Please help me how to achieve this move.
Thanks in advance
|
|
|
08-08-2012, 02:33 AM
|
#2
|
Member
Registered: Jul 2012
Posts: 30
Original Poster
Rep: 
|
Hi,
I want to move the files from one directory to another directory.
Condition i have is: file names are with spaces. Ex: "my file" , "your file".
I used the below command.
Quote:
Originally Posted by pradeepdee6
mv $current_dir/my\ file $remote_dir/their\ file
|
this moves "my file" to $remote_dir/ "their file"
But the problem im facing is i will not be knowing the name of the file. File name will be stored in a variable.
So when i used variable, the space in the file name is creating problem.
mv $current_dir/$varaible $remote_dir/ ## it ll be interpretted as mv $current_dir/my file $remote_dir/
Please help me how to achieve this move.
Thanks in advance
|
|
|
08-08-2012, 02:50 AM
|
#3
|
Member
Registered: Sep 2008
Location: Ioannina, Greece
Distribution: Gentoo
Posts: 332
Rep:
|
I'm not good at bash but have you tried double-quoting the var? Eg
Code:
mv $currentdir/"$variable" $remotedir/
|
|
|
08-08-2012, 02:59 AM
|
#4
|
Member
Registered: Jul 2012
Posts: 30
Original Poster
Rep: 
|
Thanku so much.
I have used it. But I dont want the same file name in destination.
I want to rename it with a file name having space again.
Quote:
Ex: file name in source : 123abcd.xxx xy
I want to rename in destination as : abc123d.xxx xy ( means the destination file name should have space )
|
To achive this i ll have to enter the destination file name manually.
But im running a script and it involves many files. so it wont be fesible.
Please help me with ideas to achieve this.
Thanks
|
|
|
08-08-2012, 03:09 AM
|
#5
|
Member
Registered: Sep 2008
Location: Ioannina, Greece
Distribution: Gentoo
Posts: 332
Rep:
|
Then you need to do
Code:
mv $currentdir/"$filename" $newdir/"$newfilename"
and find a way to update newfilename for every file. Spaces have nothinfg to do with this. 
|
|
1 members found this post helpful.
|
08-08-2012, 03:33 AM
|
#6
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,037
|
Also, no need to quote just a single variable, if quoting, quote the whole piece of text, like:
Code:
mv "$currentdir/$filename" "$newdir/$newfilename"
|
|
2 members found this post helpful.
|
08-08-2012, 06:52 AM
|
#7
|
Member
Registered: Jul 2012
Posts: 30
Original Poster
Rep: 
|
Thank u so much all the answers.
This really works correctly.
But im trying to work it out in XML and the out put of XML is being feeded to unix box.
Quote:
Ex: Out put of XML shuld generate -> mv "$currentdir/$filename" "$newdir/$newfilename"
|
In XML format initializing a variable is starting with a ", so when i use " in move command, it is interpretted as the ending brace.
Quote:
<assign to "variable"> from="mv "$currentdir/$filename" "$newdir/$newfilename" " </>
|
So im facing problem in generating the mv "$currentdir/$filename" "$newdir/$newfilename". (used " but didnt serve the purpose)
So is their any other way to interpret the the file name with space??
I want to try from Unix end. If i can get a way in unix then can generate XML out put in that format and input to unix box
XML Code
Thanks,
|
|
|
08-08-2012, 07:02 AM
|
#8
|
Member
Registered: Sep 2008
Location: Ioannina, Greece
Distribution: Gentoo
Posts: 332
Rep:
|
Please explain what you are EXACTLY trying to do. The original problem (as I understand it) was resolved. Now you need to escape the " in an xml tag. But then again, maybe another problem will rise. Start a new thread giving as much information as possible about your initial goal. Then describe what have you tried, what worked and what didn't.
|
|
|
08-08-2012, 07:27 AM
|
#9
|
Member
Registered: Jul 2012
Posts: 30
Original Poster
Rep: 
|
Hi,
I was trying it out manualy and mv "$currentdir/$filename" "$newdir/$newfilename" works fine.
But what im acctually supposed to do is i have to generate the mv "$currentdir/$filename" "$newdir/$newfilename" command through a XML code.
Quote:
<assign to "variable"> from="mv "$currentdir/$filename" "$newdir/$newfilename" " <\>
|
The variable is given as input to Unix box. Problem is XML code is interpreting the quote(<assign to " variable"> from= "mv ") as start and immediate next quote as end.
Im not able to use quotes efficiently.
So Im trying out to change the format of move command.
Can we use mv command to move files with name having spaces(with out using quotes ).
Is ther any way in Unix.
Please help me.
Thanks,
|
|
|
08-08-2012, 09:19 AM
|
#10
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,681
|
Quote:
Originally Posted by pradeepdee6
Hi,
I was trying it out manualy and mv "$currentdir/$filename" "$newdir/$newfilename" works fine. But what im acctually supposed to do is i have to generate the mv "$currentdir/$filename" "$newdir/$newfilename" command through a XML code.
The variable is given as input to Unix box. Problem is XML code is interpreting the quote(<assign to "variable"> from="mv ") as start and immediate next quote as end.
Im not able to use quotes efficiently. So Im trying out to change the format of move command. Can we use mv command to move files with name having spaces(with out using quotes ).
|
Pradeepdee6, you don't ever seem to post any of what you've done/tried, despite folks asking you to. You only seem to want us to do your homework/work for you:
https://www.linuxquestions.org/quest...ch-4175417736/
https://www.linuxquestions.org/quest...in-4175417783/
Post ALL the code you've written to do your specified task, and where you're stuck. There are many solutions to this...Perl has a pretty robust XML parsing library that's fairly easy to use. This has also been addressed on this site, and a Google search for "linux bash parse xml" pulls up answers too:
https://www.linuxquestions.org/quest...se-xml-798863/
http://stackoverflow.com/questions/1...se-xml-snippet
Have you done/tried ANYTHING? We are always happy to help, but you are going to have to show what effort you've put in to solving your problems, too.
|
|
|
All times are GMT -5. The time now is 12:58 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|