Open filename with special characters in Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Open filename with special characters in Perl
# 1  
Old 02-14-2008
Open filename with special characters in Perl

Hi All,
I am facing a weird problem. I have got a directory structure copied from windows to Linux. Some of the folders are named like

/gfs/data/Dow Jones $5/ DJ FCBOT_O_tick_1998.zip
/gfs/data/Dow Jones $5/ DJ FCBOT_O_tick_2000.CSV
/gfs/data/Dow Jones $5/SomeTextHere$10Futures_8811_27484684-fc45-4933-b359-88105a0d984d.CSV

I am able to read the above two lines, no problem. But, while reading the third file it gives me error: no such file and directory found.

Please suggest some good solution.

Thanks in anticipation.

Shatru.
# 2  
Old 02-14-2008
Somebody please provide me with a solution asap, its urgent.

Thanks.
# 3  
Old 02-14-2008
try tu use "file_name"
# 4  
Old 02-14-2008
Can you see the file listed in the directory if you go to it? Are you hard coding the filenames in your perl script? Did you use double-quotes when you should have used single-quotes? Post the relevent perl code that causes the error and answer the above questions.
# 5  
Old 02-14-2008
use backslash in front of the $

Code:
/gfs/data/Dow Jones $5/SomeTextHere$10Futures_8811_27484684-fc45-4933-b359-88105a0d984d.CSV 
ls /gfs/data/Dow Jones \$5/SomeTextHere\$10Futures_8811_27484684-fc45-4933-b359-88105a0d984d.CSV

You're stucture and file names are really not recommended for UNIX; you'd be much better off, removing blanks, in files/dir's, and not using special charachters.
# 6  
Old 02-14-2008
It works for me. Which kind of filesystem are you writing to? Unix-based? FAT/NTFS? or Samba shares?

Code:
# mkdir 'Dow Jones $5'
# ls
Dow Jones $5
# touch 'Dow Jones $5/Hello.txt'
# perl -e 'open(LOG, q|>>Dow Jones $5/Hello.txt|) or die $!; print LOG "This is a test\n"'
# cat Dow\ Jones\ \$5/Hello.txt
This is a test

# 7  
Old 02-14-2008
It works becuase you have properly used a single-quoted string (q||) but it will not work if you use double-quote or qq||. Hopefully the person comes back and reads this thread.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

^M special character in Filename

Hi All, Special character ? is added in between filename. Am not able to figure our why this is happening. In my Development environment special characters are not present. This issue is happening in the higher environment. It would be helpful if somebody can tell what are the possible... (3 Replies)
Discussion started by: weknowd
3 Replies

2. Shell Programming and Scripting

perl regular expression to remove the special characters

I had a string in perl script as below. Tue Augáá7 03:54:12 2012 Now I need to replace the special character with space. After removing the special chaacters Tue Aug 7 03:54:12 2012 Could anyone please help me here for writing the regular expression? Thanks in advance.. Regards, GS (1 Reply)
Discussion started by: giridhar276
1 Replies

3. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

4. Shell Programming and Scripting

Replace special characters in multiple files - perl

I have 100 files, where i want to search a set of strings and make the replacement by other strings In the first case I want to include a parameter in the name of a file LOG_DCT = $ LOG_DIR/DCT_GERAL_"$DATAINI".log replace to : LOG_DCT = $ LOG_DIR / DCT_GERAL_ $ 1_ "$ DATAINI". log I did... (1 Reply)
Discussion started by: RMSoares
1 Replies

5. Shell Programming and Scripting

special characters handling in perl

Hi, Here is my piece of code-- sub per_user_qna_detail { for($index=0;$index<@records;$index++) { if($records =~ m/^(.*)\s*Morocco.*Entering\s*Module::authenticate/) { printf "INSIDE per_user_qna_detail on LINE NO $index\n"; $Time_Stamp = $1;... (0 Replies)
Discussion started by: namishtiwari
0 Replies

6. AIX

Removing a filename which has special characters passed from a pipe with xargs

Hi, On AIX 5200-07-00 I have a find command as following to delete files from a certain location that are more than 7 days old. I am being told that I cannot use -exec option to delete files from these directories. Having said that I am more curious to know how this can be done. an sample... (3 Replies)
Discussion started by: jerardfjay
3 Replies

7. Shell Programming and Scripting

Want the substring of a string with special characters using perl

Hi, I am trying to separate the directory from the filename using the substring and it does not like it. $Complete_name="C:\ABCD\Reports_Split\090308.1630" I want $File_Name as 090308.1630 I tried using Substring function and it does not like slashes in the complete_name. Any... (5 Replies)
Discussion started by: sushma0907
5 Replies

8. Shell Programming and Scripting

remove special characters from filename recursively

hi: i have several thousand files from users and of course they use all kind of characters on filenames. I have things like: My special report (1999 ) Lisa & Jack's work.doc crazy. How do I remove all this characters in the current dir and subdirs too? Thanks. (3 Replies)
Discussion started by: jason7
3 Replies

9. Shell Programming and Scripting

remove special characters from text using PERL

Hi, I am stuck with a problem here. Suppose i have a variable which is assigned some string containing special charatcers. for eg: $a="abcdef^bbwk#kdbcd@"; I have to remove the special characters using Perl. The text is assigned to the variable implicitly. How to do it? (1 Reply)
Discussion started by: agarwal
1 Replies

10. Shell Programming and Scripting

Perl code to search for filenames that contain special characters

Hello, I have a requirement to search a directory, which contains any number of other directories for file names that contain special characters. directory structure DIR__ |__>DIR1 |__>DIR2__ |__>DIR2.1 |__>DIR2.2 |__>DIR3 .. ... (8 Replies)
Discussion started by: jerardfjay
8 Replies
Login or Register to Ask a Question