File names with spaces? Is it possible?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File names with spaces? Is it possible?
# 1  
Old 11-15-2006
Data File names with spaces? Is it possible?

Gurus -

I got one simple TXT file with long file name with blank spaces in between the words. I am trying to display that full file name, but it breaks while displaying. Could somebody shed some light here?

Script
------

for i in `cat ~\temp\employee.txt`
do
echo $i
done
# 2  
Old 11-15-2006
Quote:
Originally Posted by Eric_2005
for i in `cat ~\temp\employee.txt`
do
echo $i
done
Try this
Code:
while IFS="\n" read line
do
  echo "$line"
done < ~/temp/employee.txt

# 3  
Old 11-15-2006
Data

That really worked.

My job will be complete when i delete the files under DOCS folder, those filenames which i am retreiving from the TXT file. Below script does not seems to work to delete. Please advice.

Script
=====

cd ~/docs/

while IFS="\n" read line
do
echo "$line"
rm $line
done < ~/temp/employee.txt
# 4  
Old 11-15-2006
Try:
rm "$line"
# 5  
Old 11-15-2006
Data

Nope. that doesnt help.it is still giving "File or directory not found"
# 6  
Old 11-15-2006
Then you must have another problem besides embedded spaces in a filename. Double quotes will fix that:
Code:
$ echo testfile > "a  b"
$ cat "a  b"
testfile
$ name="a  b"
$ cat $name
cat: cannot read from file a : Is a directory
cat: cannot open file b : No such file or directory
$ cat "$name"
testfile
$ rm $name
rm: a: is a directory
rm: b: No such file or directory
$ rm "$name"
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Spaces in names between quotes

command i'm running: echo "services": "contactgroups": , | awk -F"]" '{print $1}' | cut -d' which provides the following output: check_win_semsrv_process, checking logs, check_win_semwebsrv_process, check_win_semlaunchsrv_process As you can see here, it outputs everything just... (4 Replies)
Discussion started by: SkySmart
4 Replies

2. Shell Programming and Scripting

Finding size of files with spaces in their file names

I am running a UNIX script to get unused files and their sizes from the server. The issue is arising due to the spaces present in the filename/folder names.Due to this the du -k command doesn't work properly.But I need to calculate the size of all files including the ones which have spaces in them.... (4 Replies)
Discussion started by: INNSAV1
4 Replies

3. OS X (Apple)

Remove leading spaces from file names and folders

Hi All, I have a vexing issue with leading spaces in file names. Basically, we're moving tons of data from our ancient afp file share to Box.com and Box forbids leading spaces in files or folders. The HFS file system seems to be perfectly fine with this, but almost all other Unix file systems... (1 Reply)
Discussion started by: prometheon123
1 Replies

4. Shell Programming and Scripting

Remove spaces from start of file names

Hi, I have a directory with the following file names 01 - abc hyn 02-def 03-ghi.dir 04 - jhu.dir abc1 kil def bil The last two file names abc1 starts with one space and def starts with double space. I want these files in my directory to be renamed as ABC HYN DEF GHI.dir... (6 Replies)
Discussion started by: jacobs.smith
6 Replies

5. Shell Programming and Scripting

The "read" command misinterprets file names containing spaces

The "read" command, which is built into bash, takes words from the standard input. However, "read" is not good at taking file names if the file names contain spaces. I would like my bash script to ask the user to enter file names, which may contain spaces. Can you think about any technique for... (14 Replies)
Discussion started by: LessNux
14 Replies

6. Shell Programming and Scripting

How to strip the spaces in file names?

please somebody tell me what is wrong with this, while the thumbnail grabbing works and encoding works, but what is not working is, mv $i.jpg /var/www/thumbs/ and mv $i.mp4 /var/www/uploads/ #!/bin/bash # MINT 9 - FFMPEG - QT-FASTSTART - X264 - MP4 DIR=/var/www/tmp for i in... (9 Replies)
Discussion started by: mysoogal
9 Replies

7. Shell Programming and Scripting

Opening File names with spaces inside it !- PERL

I developed a perl code..And the excerpt from it is given below... open(HANDLE,$cmp_path) ; #reading the xml file from the file path while($file_path = <HANDLE>) I have list of XML files to read from a folder. It has some spaces inside the name of the file...I used "\"... (2 Replies)
Discussion started by: gameboy87
2 Replies

8. Shell Programming and Scripting

Remove spaces between file names

Hi All, I have spaces in between file names. "Material Header.txt" "Customer Header.txt" "Vendor Header.txt" And how can I remove spaces between file names like below MaterialHeader.txt CustomerHeader.txt VendorHeader.txt Thanks Srimitta (10 Replies)
Discussion started by: srimitta
10 Replies

9. UNIX for Dummies Questions & Answers

Unable to use mimesender to send attachments with spaces in the file names / paths

Hello, I found the mimesender multiple attachment emailing shell script in the FAQ of these forums, and I have been able to use it to send multiple files, but only if they don't have spaces in their file name or path. When I attempt to send a file with spaces in it's name, enclosed... (0 Replies)
Discussion started by: rsmorra
0 Replies

10. Shell Programming and Scripting

Dealing with spaces in file names in a shell script

Hi, What's the best way to find all files under a directory - including ones with space - in order to apply a command to each of them. For instance I want get a list of files under a directory and generate a checksum for each file. Here's the csh script: #!/bin/csh set files = `find $1... (5 Replies)
Discussion started by: same1290
5 Replies
Login or Register to Ask a Question