473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Space in file name problem

Hi

I am faceing a problem with a space in file name.
I want to write a script which will open a file that file contain others file name, among them few file name contain space.
>cat checkfile
file1
file2
new file
file no

Here the file 'new file' and 'file no' contain space.When i trying to print contain of the file 'new file' from for loop it is giving error like,
cat: new: No such file or directory
cat: file: No such file or directory
cat: file: No such file or directory
cat: no: No such file or directory


Please give suggestion how do i resolve.Thanks in advance.

Thanks,
-ASK
Aug 22 '08 #1
9 9338
Nepomuk
3,112 Expert 2GB
>cat checkfile
file1
file2
new file
file no

Here the file 'new file' and 'file no' contain space.When i trying to print contain of the file 'new file' from for loop it is giving error like,
cat: new: No such file or directory
cat: file: No such file or directory
cat: file: No such file or directory
cat: no: No such file or directory
Try this:
Expand|Select|Wrap|Line Numbers
  1. >cat checkfile
  2. file1
  3. file2
  4. new\ file
  5. file\ no
Note the backslashes - I'm escaping the space. I think, this way it should work fine.

Greetings,
Nepomuk
Aug 22 '08 #2
No It is not wroking.

As i told you i am getting problem in for loop.

This chechfile is the input in for loop,
As the for loop iterates based on space so \, ", ' anything is not wroking.

Pls, try like this open that checkfile in for loop and then trying to print the containt of each file from checkfile.

How do i resolve .Thank in advance.

-Ashok
Aug 23 '08 #3
Nepomuk
3,112 Expert 2GB
No It is not wroking.

As i told you i am getting problem in for loop.

This chechfile is the input in for loop,
As the for loop iterates based on space so \, ", ' anything is not wroking.

Pls, try like this open that checkfile in for loop and then trying to print the containt of each file from checkfile.

How do i resolve .Thank in advance.

-Ashok
Well, it's difficult to find a solution without having the code. Could you post the relevant parts of this shell script?

Also, is the error message still the same?

Greetings,
Nepomuk
Aug 23 '08 #4
Error Msg i have posted at first place.
Aug 23 '08 #5
Just a for loop, input is the checkfile(which contain few file names )
Inside using cat for each file.
Thats it. You try, I am sure u will also face the same problem.

There must be some way to use files and folders which contain space in script.

Best Regards,
Ashok
Aug 23 '08 #6
Nepomuk
3,112 Expert 2GB
Error Msg i have posted at first place.
OK, so it's still the same error message. Exactly the same?
Just a for loop, input is the checkfile(which contain few file names )
Inside using cat for each file.
Thats it. You try, I am sure u will also face the same problem.
That's not the point. We want to make your code work, so please post your code! I'm sure, we'll be able to solve the problem then.

Greetings,
Nepomuk
Aug 23 '08 #7
ghostdog74
511 Expert 256MB
don't use for loop with cat. Use while read loop instead to iterate a file
Expand|Select|Wrap|Line Numbers
  1. while read line
  2. do
  3.  # echo $line
  4. done < file
  5.  
Aug 23 '08 #8
What is the difference by reading with for to while loop.
Can you please elaborate a little.

Thanks for your suggestion.


I found out the above solution first convert the space before for loop to some other rearly used character. then inside for loop do the opposite by sed command.

Thanks for your time.
-Ask
Aug 23 '08 #9
ghostdog74
511 Expert 256MB
functions wise, there is no difference. They are just loops. Syntactically, they are different. PLease look through the bash reference manual for more information. I am just only advising on the caveats you will encounter when using a for cat loop to iterate a file. Special care need to be taken to ensure white spaces is escaped properly.
Aug 24 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows...
5
by: alain | last post by:
Good morning to you all, The problem : i use the shell command and i used, with W98, to use the DOS name when there was a space in the file / folder name ( ex : Program~1 for Program Files). With...
3
by: adgnews | last post by:
I have a problem converting a program from Vb.net VS2003 to VS2005. I process a xml-file with an inline schema. In 2003 no problem. In 2005 I have 2 problems: 1) BIG space="preserve" problem....
8
by: Dave G | last post by:
I know this is an old favourite but I can't find a simple answer to a simple question. I'm trying to run this: shell("c:\program files\pkware\pkzipc\pkzipc.exe -ext " & myPath & myZIPFile & "...
12
by: snow | last post by:
Hi All, I noticed if file path has a white space, for example "C:\my document \test.txt", the function File.Exists(filePath) always return false in release mode. How could I make this function...
3
by: kvnsmnsn | last post by:
I've written the following Javascript file that includes an input text field and an output text field, the latter of which is initialized to zero. Each time the user enters a number in the input...
3
by: skyy | last post by:
Hi.. i have a string that i would want split on a single blank space only. eg. $string = File: abc.txt using split with white space i can get the name of the file : abc.txt However i run...
7
by: lawrence k | last post by:
I've got a music studio for a client. Their whole studio is run with Macintosh computers. Macintosh computers allow file names to have open white spaces, such as "animal hospital.mp3". I have a...
2
by: Joseph J. Kesselman | last post by:
Gabe wrote: You can do exactly that, exactly as you've shown it: <nameJohn Smith</name> But... Now you aren't talking about XML -- you're talking about the behavior of the tool you're...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.