Find command error having space in filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find command error having space in filename
# 1  
Old 06-10-2013
Find command error having space in filename

Hi,

I am working in solaris.I am using below script to copy the files from /usr/tmp to /usr/gm
But while running this it is not considering the files list after the filename having space in them.

Example:-
compile_custom_pll.sh
conv_data_sqlload.sh
conv_sqlload.sh
Copy of compile_custom_pll.sh=>From here below files are notconsidered
Copy of conv_data_sqlload.sh
Copy of conv_sqlload.sh
long_XXCUS_INV_Item_STG.ctl
pb_load.sh
smc_extra_items.sh

Code:
 
/usr/xpg4/bin/find /usr/tmp -type f -name "*.fmt" -o -name "*.sh" -o -name "*.ctl" | while read filename
  
do
  
echo "Copying $filename to /usr/gm" 
      
cp -f $filename /usr/gm  
if [ $? != 0 ];then
 echo "$filename could not copied to $dest !!!!!!!"
 exit 7
fi
done


Could you please help me how to do this using solaris
# 2  
Old 06-10-2013
Put double quotes aroud filename
Code:
cp -f "$filename" /usr/gm

# 3  
Old 06-11-2013
Hi,

I am searching the ISC_DEPOT_RO_INIT in the files present in /usr/tmp but it is failing when the file have space in their name.For example here i have a file "hello Kevin"

Please suggest what changes i should do here.

/usr/tmp/Sql/APWUPDST.sql:0
/usr/tmp/sanj.test:1
grep: can't open "/usr/tmp/hello"
grep: can't open "Kevin"

Code:
 
/usr/xpg4/bin/grep -ixlc "ISC_DEPOT_RO_INIT" `/usr/xpg4/bin/find "/usr/tmp" -type f`

# 4  
Old 06-11-2013
Do the simpler way Smilie

Code:
/usr/xpg4/bin/find /usr/tmp -type f -name "*.fmt" -o -name "*.sh" -o -name "*.ctl" -exec cp -f {} /usr/gm/ \;

# 5  
Old 06-11-2013
I am not copying ..i am doing grep here...

Code:
 
/usr/xpg4/bin/grep -ixlc "ISC_DEPOT_RO_INIT" `/usr/xpg4/bin/find "/usr/tmp" -type f`

# 6  
Old 06-11-2013
The first post did say that you had issues with copying files with spaces in their names. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find command with Metacharacter (*) Should match exact filename

Hi, Below is list of files in my directory. -rw-rw-r--. 1 Roots Roots 0 Dec 26 06:58 12345_kms_report.csv -rw-rw-r--. 1 Roots Roots 0 Dec 26 06:59 12346_kms_report.csv -rw-rw-r--. 1 Roots Roots 0 Dec 26 06:59 12347_kms_report.csv -rw-rw-r--. 1 Roots Roots 0 Dec 26 06:59... (2 Replies)
Discussion started by: Balraj
2 Replies

2. Shell Programming and Scripting

Find files where filename ends with space

Hello all, I would like to find files where the filename ends with a space - like Test.dat I tried it with: #!/bin/bash for file in $(find . -name 'Test.dat*') do echo "($file)" done I found the file I have searched for - but unfortunately the output is as: (Test.dat) But I... (11 Replies)
Discussion started by: API
11 Replies

3. Shell Programming and Scripting

Print filename/dir name while executing aclput using find command

Running below command , but unable to print the filename , is there way to print filename/dirname using -print option find . -type f -exec aclput -i fileacl.template {} \; (5 Replies)
Discussion started by: lalitpct
5 Replies

4. UNIX for Dummies Questions & Answers

Find command fails when a space is in the directory path variable

I have a script like this running under OS X 10.8. The problem arises when the find command encounters a space in the path name. I need the "dir" variable as I'll be extending the script to more general use. #!/bin/bash CFS=$IFS IFS=$(echo) set dir = "/Users/apta/Library/Mail\... (3 Replies)
Discussion started by: apta
3 Replies

5. Shell Programming and Scripting

Only filename from find command

Hi All When we use find command command in Unix we get the result as /home/user/folder/filename1 /home/user/folder/filename2 /home/user/folder/filename3 Is it possible that i only get the file name The expected output when using find command is filename1 filename2 filename3 I am... (13 Replies)
Discussion started by: parthmittal2007
13 Replies

6. UNIX for Dummies Questions & Answers

filename with white space

our user creates a text file with a white space on the filename. this same file is transfered to unix via automation tool. i have a korn shell script that reads these files on a input directory and connects to oracle database to run the oracle procedures which will load the data from each of the... (2 Replies)
Discussion started by: wtolentino
2 Replies

7. Shell Programming and Scripting

Howto get only filename from find command in Linux?

Hi every body! I would like to get only filename in the result of find command in Linux but I don't know howto. Tks so much for your helps. (5 Replies)
Discussion started by: nguyendu0102
5 Replies

8. Shell Programming and Scripting

how to get only filename in a recursively find command

Hi i would like to ask on how to accomplish the FF: I want to execute a find command recursively and only get the filename something like i want only the last field set if is used ever the fieldvset as an redirection from the output of the find command For example: dir1/dir2/filename1... (2 Replies)
Discussion started by: jao_madn
2 Replies

9. Solaris

command to find free disk space on solaris

In linux df is the command to find free space what is the equivalent command in the Solaris (2 Replies)
Discussion started by: harishankar
2 Replies

10. UNIX for Dummies Questions & Answers

search for hardlinks based on filename via find command

I am using command substitution into a find command in a script where I have built a menu to do a bunch of tasks within my unix account. When I choose the options for to find a file/files that have the same inode of the entered filename, ie hardlinks, nothing shows up. When I choose the appropiate... (2 Replies)
Discussion started by: hunternjb
2 Replies
Login or Register to Ask a Question