filename with white space


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers filename with white space
# 1  
Old 01-09-2012
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 files. it appears to be that my code does not recognize a file that has a white space on it's filename. i am using a simple for loop with a combination of ls -1 *.* commands on my code. i think i might be missing something.

below is the sample of snippet of the code that i use to simulate the result.
Code:
#!/usr/bin/ksh
cd /u02/app/bdms/dev/in
echo "simple ls -latr results in:\n"
ls -latr
echo "\n"
echo "when using for loop:"
for filename in $(ls -1 *.*)
do
 echo "files: $filename"
done
cd $HOME/apps

when the above code is run below is the results.
Code:
$ sh sample_dirlist.sh
simple ls -latr results in:

total 16
drwxr-xr-x    3 oracle   oracle          256 Aug 20 2009  ..
-rw-rw----    1 bdmsftdv staff          1174 Jan 06 16:43 Test 1 LFD.csv
drwxrwx---    2 bdmsftdv bdmsgrp         256 Jan 06 17:07 .
-rw-rw----    1 bdmsftdv staff          1204 Jan 09 13:59 Test 2 LFD.csv


when using for loop:
files: Test
files: 1
files: LFD.csv
files: Test
files: 2
files: LFD.csv

please help. thank you.
# 2  
Old 01-09-2012
*.* is a DOS thing, to specify all files in UNIX only * is necessary.

That's a useless use of ls * and useless use of backticks besides.

Do it without the ls and it works.

Code:
for FILE in *
do
        echo "File is $FILE"
done

Be careful to always quote the filename when you use it. mv $FILE destination/ will mess up when $FILE contains spaces, mv "$FILE" destination/ won't.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 01-09-2012
thanks so much that works
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add white space

hi guys how can i add spacein file name with sed if strings have no space around dash input 19-20 ( 18-19 ) ABC-EFG output after add white space 19 - 20 (18 - 19 ) ABC - EFG thx in advance (2 Replies)
Discussion started by: mhs
2 Replies

2. Shell Programming and Scripting

Removing white space in awk

Hi How to remove white space from this input:|blue | 1| |green| 4| |black| 2| I like to search for green and get 4not 4 How to modify this to work correct:awk -F"|" '/green/ {print $3} (7 Replies)
Discussion started by: Jotne
7 Replies

3. Shell Programming and Scripting

Remove unwanted white space

Hi, I have a very big file 25GB with information present in it like $ head ind_stats update index statistics pfirm001.dbo.Office using 200 values go ... (11 Replies)
Discussion started by: sam05121988
11 Replies

4. Shell Programming and Scripting

AWK - Ignoring White Space with FS

I have an AWK script that uses multiple delimiters in the FS variable. FS="+" My awk script takes a file name such as this: 12345_smith_bubba_12345_20120215_4_0.pdf and parses it out based on the under score. Each parsed field then has some code for data validation etc. This script has... (12 Replies)
Discussion started by: reno4me
12 Replies

5. Shell Programming and Scripting

Replacing white spaces in filename

Hi; In following code find LOG_DIR -type f | while read filename; do echo $filename; done I want to precede each white space encountered in filename with \ so that when i use $filename for running some commands in do...done,it wont give me an error. will appreciate ur help in this.... (1 Reply)
Discussion started by: ajaypadvi
1 Replies

6. Shell Programming and Scripting

Delete white space using sed

Hi , I have a file with contents as below group1 = aaaaa, bbbbb, ccccc, aaa group2=aaa, bbbbb, ccccc, aaaaa group3 = bbbbb, aaa, ccccc, aaaaa group4 = bbbbb, aaa,ccccc, aaaaa I want to search for "aaa" and the output should be as below group1 = aaaaa, bbbbb, ccccc group2= bbbbb, ccccc,... (3 Replies)
Discussion started by: anil8103
3 Replies

7. Shell Programming and Scripting

sed + white space

Hi, What sed command (if sed is the right command) can remove ALL white space from my file. I have a csv, except I want to remove all white space between commas and characters. My idea (without testing) sed 's/ //g' Is there a better way? (18 Replies)
Discussion started by: mcclunyboy
18 Replies

8. UNIX for Dummies Questions & Answers

SED with White Space

Dear Members, Suppose i have a variable test which stores a string as below: test='John drives+++++++++a+++++car' now i want to use sed on the above variable and replace + with a white space, so that i get echo $test should give me 'john drives a car' Between... (1 Reply)
Discussion started by: sandeep_1105
1 Replies

9. UNIX for Dummies Questions & Answers

Padding With White Space Between Variables

Dear Users, How do we pad with white space of particular length between two variables. For Example: Suppose i define the variables as follows: a='toyota' b='camry' c='honda' d='accord' e=`echo "$a"'\n'"$b"` f=`echo "$c"'\n'"$d"` If i do an echo on variables e and f i get :... (1 Reply)
Discussion started by: sandeep_1105
1 Replies

10. Shell Programming and Scripting

stripping white space...

Hi All; Having a problem with a file.. the file contains the following data... (a snapshot) 1331F9E9DB7C2BB80EAEDE3A8F043B94,AL7 1DZ,M,50 186FDF93E1303DBA217279EC3671EA91,NG5 1JU,M,24 3783FFAF602015056A8CD21104B1AAAF,CH42 4NQ,M,17 It has 3 columns sepreated by a , the second column... (7 Replies)
Discussion started by: Zak
7 Replies
Login or Register to Ask a Question