moving a file having blanks in its name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting moving a file having blanks in its name
# 1  
Old 10-15-2008
Error moving a file having blanks in its name

Hi ,
i need to write a simple to script in KSh to move some files ,
but these files have spaces in there name, resulting in error in transfering

eg i have following files
30222_Deal Ticket_20071227203.csv
30222_Deal Ticket_20071227204.csv
30222_Deal Ticket_20071227205.csv

and i want to move them to some other folder ,
i am using follwing script

for i in `ls *20071227*`
do
cp "$i" ./NewFolder
done

this script gives error
cp: cannot access 30222_Deal
cp: cannot access Ticket_20071227203.csv


Please help Smilie
# 2  
Old 10-15-2008
Look like you don't have permissions to read that files.
# 3  
Old 10-15-2008
Permissions are available,
just try to replicate the scenario mentioned above
# 4  
Old 10-15-2008
You don't have any space in your file names and you don't really need ls
Code:
$ for i in *20071227*; do echo cp $i ./NewFolder;done
cp Ticket_20071227203.csv ./NewFolder
cp Ticket_20071227204.csv ./NewFolder
cp Ticket_20071227205.csv ./NewFolder
$ ls NewFolder/
Ticket_20071227203.csv  Ticket_20071227204.csv  Ticket_20071227205.csv

Your problem is:
Quote:
Originally Posted by Anand28
cp: cannot access 30222_Deal
cp: cannot access Ticket_20071227203.csv
# 5  
Old 10-15-2008

Not only is ls unnecessary, it is breaking your script.

Use wildcard expansion directly:

Code:
cp *20071227* ./NewFolder

Similarly, when you need to use a loop (which you don't in this case):

Code:
for i in *20071227*
do
  cp "$i" ./NewFolder
done

# 6  
Old 10-15-2008
actually these are 3 files
1.) 30222_Deal Ticket_20071227203.csv
2.) 30222_Deal Ticket_20071227204.csv
3.) 30222_Deal Ticket_20071227205.csv

and they have spaces in between
# 7  
Old 10-15-2008
oh, yes cp is working without ls
but can any one explian how and why this is creating a problem
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need help on moving .csv file from UNIX to windows file path

Need help on moving .csv file from unix to windows file path. (1 Reply)
Discussion started by: lakshmanraok117
1 Replies

2. Shell Programming and Scripting

Leading blanks

Hi Ich have a list as follows 73 5 100 45 81 4 and I would like to have an output (on screen) like that 73 5 100 45 81 4 (6 Replies)
Discussion started by: lazybaer
6 Replies

3. Shell Programming and Scripting

Deleting all the fields(columns) from a .csv file if all rows in that columns are blanks

Hi Friends, I have come across some files where some of the columns don not have data. Key, Data1,Data2,Data3,Data4,Data5 A,5,6,,10,, A,3,4,,3,, B,1,,4,5,, B,2,,3,4,, If we see the above data on Data5 column do not have any row got filled. So remove only that column(Here Data5) and... (4 Replies)
Discussion started by: ks_reddy
4 Replies

4. Shell Programming and Scripting

Need help in finding filesize , moving file , gzipping file

Hi , Please help with the following questions 1) how can i find size of a file ? i have written du -k $flname > s1 . Is this right ? Any other better suggeastions ? 2) how do I use mv command for moving the file ? I need the syntax with some examples 3) Command for printing the total... (1 Reply)
Discussion started by: Learning!
1 Replies

5. Shell Programming and Scripting

Removing blanks in a text tab delimited file

Hi Experts I am very new to perl and need to make a script using perl. I would like to remove blanks in a text tab delimited file in in a specfic column range ( colum 21 to column 43) sample input and output shown below : Input: 117 102 650 652 654 656 117 93 95... (3 Replies)
Discussion started by: Faisal Riaz
3 Replies

6. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

7. Programming

Blanks vs: Nulls

I'm relatively new to Pro*C programming. In the following example: char name; EXEC SQL SELECT 'John Doe' INTO :name FROM DUAL; "John Doe" is in positions 0-7, blanks in 8-19, and a null in 20. I would really prefer the null to be in position 8 and I don't care what's after that. I wrote a... (1 Reply)
Discussion started by: ebock
1 Replies

8. UNIX for Advanced & Expert Users

numbering blanks

hello i'm trying to figure out how to number a blank line. For instance this : sed '/./=' file | sed '/./N; s/\n/ /' gives me 1 aaaa 2 bbbbbb 4 cccccc 5 ffkkkfff 6 ffsdfdfs I would like something like this: 1 aaaaa 2 3 bbbbbb 4 5 cccccc And so... (6 Replies)
Discussion started by: wisher115
6 Replies

9. Shell Programming and Scripting

blanks in file name

I have a file with a list of filenames. I want to work loopwise through the file and operate on each of the listed files. Normally I'd do something like: for file in `cat $mydir/file-list` do echo $file >> $mydir/my.log cp $mydir/$file $newdir done the problem is that my... (1 Reply)
Discussion started by: LisaS
1 Replies

10. UNIX for Dummies Questions & Answers

moving a file?

i'm trying to move a file from one diectory to another and rename it at the same time. but its giving me an error . " mv: cannot unlink /dir2/file5 : No such file or directory" here is the command I'm using. mv /dir1/file1 /dir2/file5 solaris 8 (1 Reply)
Discussion started by: Holistic
1 Replies
Login or Register to Ask a Question