473,651 Members | 2,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Space in file name problem

30 New Member
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 9358
Nepomuk
3,112 Recognized Expert Specialist
>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
ashokd001
30 New Member
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 Recognized Expert Specialist
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
ashokd001
30 New Member
Error Msg i have posted at first place.
Aug 23 '08 #5
ashokd001
30 New Member
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 Recognized Expert Specialist
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 Recognized Expert Contributor
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
ashokd001
30 New Member
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 Recognized Expert Contributor
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
2156
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 XP Pro SP 1, .Net Framework 1.1) and on our production server (Windows 2K SP 4, .Net Framework 1.1). I have simplified the code and data to isolate the problem. When I use the xsl:strip-space (Line 12) declaration in conjunction with the xsl:sort...
5
6270
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 XP, I don't find that sort of replacement name when i run command and then DIR command to reach the DOS names of the files / folder. How could i do to use correctly the shell command with files / folders with a space in their name ? Thank you. ...
3
1710
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. Suddenly the spaces are a problem during processing (The following text is not allowed in this context: ' '). Without the space="preserve" (or default) it works okay, but what to do now since I can't influence the dataformat.
8
16439
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 & " " & myPath) I want to unzip a file who's path name is defined by the variable myPath and who's file name is defined by the variable myZIPFile, and
12
4544
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 work for the file which is located in a direcotry with a white space? Thanks!
3
2861
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 field and hits the space bar, that number gets added to the value in the output field and then the input field gets set to the empty string. The user can enter as many numbers into the input field as s/he wants. The problem I have with this is...
3
2177
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 into problem when there is many spaces in the filename. eg.
7
2627
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 download script, so customers on the website can download MP3s to their harddrive (rather than merely listen to it in their browsers):
2
1617
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 passing the XML to.
0
8792
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8694
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8457
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8571
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7294
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.