Re: Problem using non-standard filenames
Re: Problem using non-standard filenames
am 26.10.2007 15:03:34 von Janis Papanagnou
GT wrote:
> Hi all,
> Hopefully I can get some help here.
> I am using gfortran / linux and have to read data files.
> In short.
> The problem boils down to the fact that these files have names that include
> spaces and brackets and quotes etc ... basically if it is a name winword
> (or windows in general) will allow the files are likely to use them.
> This is because the labs sending us the files use windows, as well as other
> systems.
> So, the problem is that, in the end, I have to use fortran to get and open
> these files.
>
> eg :
> file name =
> SIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) ][SEC=UNCLASSIFIE D260.txt
>
> ->
>
> knowin bash will take quotes I do :
>
> file_name=
> "CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt"
>
> then, naïvely :
> open(unit=xx,file=file_name)
> won't work since it looks for
>
> "CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt"
>
> not
>
> CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt
>
> bottom line, as I see it, is that shell understands separate words as
> entities to act upon separately. Windows does not, depending on the command
> used : notepad as it
> will open notepad and create a file called "as it.txt"
> try the same under shell (using vi for instance) and you will be editing two
> files, sequentially.
>
> So, there's my problem: reading the original file names is no problem (ls
> the dir into a file then read the lines : you have the filenames), getting
> them (opening them) is quite another because of those spaces and other
> nasty characters.
>
> So, question is : how, using the multi-powerful unix/linux system can I
> CHANGE file names OF THE FILES by removing non-standard alphanumeric chars?
> So, for instance :
> CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt
>
> -> CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TXT
The fortran problem is a mystery to me, but to remove "strange" characters
with bash on Linux is easiest done by removing everything that is not an
alphanumeric character or the dot using variable substitution...
f="CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt"
echo "${f//[^[:alnum:].]}"
will produce
CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.txt
Use a loop to iterate over all files in a directory and rename them...
for f in *
do
mv -i "$f" "${f//[^[:alnum:].]}"
done
Hope that helps.
Janis
>
> (and then I simply ls the dir into a file, read those file names and open
> them normally since there are no nasty chars)
>
> so the equivalent to
> cp CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt
> CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TXT
>
> which would be done by :
> cp "CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt"
> CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TXT
>
> which cannot be done through fortran's call system for the reason above.
>
> (assuming no limit on filename length)
> Specifying those unwanted chars is no problem since there aren't that many.
>
> Thank you for any help here. I am s t u c k !
>
> G
Re: Problem using non-standard filenames
am 26.10.2007 16:01:52 von huge
On 2007-10-26, GT wrote:
> Hi all,
> So, question is : how, using the multi-powerful unix/linux system can I
> CHANGE file names OF THE FILES by removing non-standard alphanumeric chars?
> So, for instance :
> CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt
>
> -> CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TXT
>
> (and then I simply ls the dir into a file, read those file names and open
> them normally since there are no nasty chars)
I have a set of perl scripts for dealing with this kind of stuff.
(Please, no criticism of the layout - my interest in religious issues is
indicated by my .sig)
'unspace' changes multiple spaces to single underscores;
#!/usr/bin/perl
foreach $_ (@ARGV)
{
$o = $_;
s/ +/_/g;
if (! -e $_)
{
rename ($o, $_) || die "Couldn't rename $o - $!\n";
}
}
'lower' converts the filenames to lower case (because of uniqueness/sorting
issues between Unix & Winblows);
#!/usr/bin/perl
foreach $_ (@ARGV)
{
$orig = $_;
tr/A-Z/a-z/;
if (! -e $_)
{
rename ($orig, $_) || die "Couldn't rename $orig - $!\n";
}
}
And 'normalise' removes weird chars from filenames. You pass it the list of
characters you want to remove and the filenames you want to change, like;
normalise "()[]=," *
#!/usr/bin/perl
$chars = shift;
@chars = split(//,$chars);
foreach $char (@chars)
{
$char =~ s/\(/\\(/;
$char =~ s/\)/\\)/;
$char =~ s/\$/\\\$/;
}
foreach $_ (@ARGV)
{
$o = $_;
foreach $char (@chars)
{
s/$char//g;
}
next if ($o eq $_);
if (! -e $_)
{
rename ($o, $_) || die "Couldn't rename $o: $!\n";
}
else
{
print "Couldn't rename $o, $_ already exists.\n";
}
}
--
"Be thankful that you have a life, and forsake your vain
and presumptuous desire for a second one."
[email me at huge {at} huge (dot) org uk]
Re: Problem using non-standard filenames
am 26.10.2007 16:43:11 von Janis Papanagnou
Please don't top-post!
Top-posting makes it really hard to refer to quotes at approriate places.
I won't fix your posting style; go and collect the information below...
GT wrote:
> Pretty much thank you,
> I tried it, and it works, but I need to do this for a number of dirs.
> So, I get the name of the dir and can use it through
> call system ('source rename.sh '//dir_name)
> where dir_name is a fortran variable containing sequentially all dir names,
> and rename.sh is your script.
I don't understand what role your Fortran code plays here.
>
> I tried changing dir by putting directory names instead of the * but got
> strange results.
> The grand finale, which is actually what I am after, is outputing the list
> of all the (now correct) filenames, to a file, reading the filenames and,
> at last, be able to read the contents !!
To list filenames see (somewhere) below.
>
> So, how do I introduce these changes ? Must be trivial I know.
>
> So ,recapping :
>
> dir_name==dir1,dir2,....,dirN
> call system("source rename.sh "//dir_name)
Again, I don't understand what role your Fortran code plays.
To sequentially enter a fixed set of directories to perform some task...
for d in dir1 dir2 dir3 dirN
do (
cd "$d"
whatever-to-do-in-directory ###
)
done
At the marked ### line you may add the "for f" loop I showed below; but
note that the output redirection " > file_with_new_filenames" should
then go to the outer, enclosing loop, otherwise the list of filenames
would get overwritten with every new processed directory.
>
> this corrects the file names of all files in all N dirs. Then these file
> names are ls'd to a file so they can be read by fortran to be used.
>
>
> Thanks for your help.
>
> G.
>
>
>
>> f="CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340)
>> [SEC=UNCLASSIFIED]260.txt" echo "${f//[^[:alnum:].]}"
>>
>>will produce
>>
>> CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.txt
>>
>>Use a loop to iterate over all files in a directory and rename them...
>>
>> for f in *
>> do
>> mv -i "$f" "${f//[^[:alnum:].]}"
>> done
Rename files and create a list of filenames in a file....
for f in *
do
mv -i "$f" "${f//[^[:alnum:].]}"
echo "${f//[^[:alnum:].]}"
done > file_with_new_filenames
>>
>>Hope that helps.
>>
>>Janis
>>
>>
>>>(and then I simply ls the dir into a file, read those file names and open
>>>them normally since there are no nasty chars)
>>>
>>>so the equivalent to
>>>cp CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340)
>>>[SEC=UNCLASSIFIED]260.txt
>>>CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TXT
>>>
>>>which would be done by :
>>>cp "CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340)
>>>[SEC=UNCLASSIFIED]260.txt"
>>>CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TXT
>>>
>>>which cannot be done through fortran's call system for the reason above.
>>>
>>>(assuming no limit on filename length)
>>>Specifying those unwanted chars is no problem since there aren't that
>>>many.
>>>
>>>Thank you for any help here. I am s t u c k !
>>>
>>>G
>
>
Problem using non-standard filenames
am 26.10.2007 16:49:02 von GT
Hi all,
Hopefully I can get some help here.
I am using gfortran / linux and have to read data files.
In short.
The problem boils down to the fact that these files have names that include
spaces and brackets and quotes etc ... basically if it is a name winword
(or windows in general) will allow the files are likely to use them.
This is because the labs sending us the files use windows, as well as other
systems.
So, the problem is that, in the end, I have to use fortran to get and open
these files.
eg :
file name =
SIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) ][SEC=UNCLASSIFIE D260.txt
->
knowin bash will take quotes I do :
file_name=
"CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt"
then, naïvely :
open(unit=xx,file=file_name)
won't work since it looks for
"CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt"
not
CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt
bottom line, as I see it, is that shell understands separate words as
entities to act upon separately. Windows does not, depending on the command
used : notepad as it
will open notepad and create a file called "as it.txt"
try the same under shell (using vi for instance) and you will be editing two
files, sequentially.
So, there's my problem: reading the original file names is no problem (ls
the dir into a file then read the lines : you have the filenames), getting
them (opening them) is quite another because of those spaces and other
nasty characters.
So, question is : how, using the multi-powerful unix/linux system can I
CHANGE file names OF THE FILES by removing non-standard alphanumeric chars?
So, for instance :
CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt
-> CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TXT
(and then I simply ls the dir into a file, read those file names and open
them normally since there are no nasty chars)
so the equivalent to
cp CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt
CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TXT
which would be done by :
cp "CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt"
CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TXT
which cannot be done through fortran's call system for the reason above.
(assuming no limit on filename length)
Specifying those unwanted chars is no problem since there aren't that many.
Thank you for any help here. I am s t u c k !
G
Re: Problem using non-standard filenames
am 26.10.2007 17:20:43 von OldSchool
On Oct 26, 10:01 am, Huge wrote:
> On 2007-10-26, GT wrote:
>
> > Hi all,
> > So, question is : how, using the multi-powerful unix/linux system can I
> > CHANGE file names OF THE FILES by removing non-standard alphanumeric chars?
> > So, for instance :
> > CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340) [SEC=UNCLASSIFIED]260.txt
>
> > -> CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TXT
>
> > (and then I simply ls the dir into a file, read those file names and open
> > them normally since there are no nasty chars)
>
> I have a set of perl scripts for dealing with this kind of stuff.
>
> (Please, no criticism of the layout - my interest in religious issues is
> indicated by my .sig)
>
> 'unspace' changes multiple spaces to single underscores;
>
> #!/usr/bin/perl
>
> foreach $_ (@ARGV)
> {
> $o = $_;
> s/ +/_/g;
> if (! -e $_)
> {
> rename ($o, $_) || die "Couldn't rename $o - $!\n";
> }
> }
>
> 'lower' converts the filenames to lower case (because of uniqueness/sorting
> issues between Unix & Winblows);
>
> #!/usr/bin/perl
>
> foreach $_ (@ARGV)
> {
> $orig = $_;
> tr/A-Z/a-z/;
> if (! -e $_)
> {
> rename ($orig, $_) || die "Couldn't rename $orig - $!\n";
> }
> }
>
> And 'normalise' removes weird chars from filenames. You pass it the list of
> characters you want to remove and the filenames you want to change, like;
>
> normalise "()[]=," *
>
> #!/usr/bin/perl
>
> $chars = shift;
> @chars = split(//,$chars);
>
> foreach $char (@chars)
> {
> $char =~ s/\(/\\(/;
> $char =~ s/\)/\\)/;
> $char =~ s/\$/\\\$/;
> }
>
> foreach $_ (@ARGV)
> {
> $o = $_;
> foreach $char (@chars)
> {
> s/$char//g;
> }
>
> next if ($o eq $_);
>
> if (! -e $_)
> {
> rename ($o, $_) || die "Couldn't rename $o: $!\n";
> }
> else
> {
> print "Couldn't rename $o, $_ already exists.\n";
> }
> }
>
> --
> "Be thankful that you have a life, and forsake your vain
> and presumptuous desire for a second one."
> [email me at huge {at} huge (dot) org uk]
since you don't say *how* you are getting the "list of filenames" into
*fortran* the problem is hard to diagnose.
this should be dead easy if your reading them from a file one line at
a time. in that case *don't quote the names in the file*.
if they're being passed as quoted strings from the shell to an arg
list, you should be able to just strip the leading/trailing quote and
run w/ it
Re: Problem using non-standard filenames
am 26.10.2007 17:55:13 von GT
Pretty much thank you,
I tried it, and it works, but I need to do this for a number of dirs.
So, I get the name of the dir and can use it through
call system ('source rename.sh '//dir_name)
where dir_name is a fortran variable containing sequentially all dir names,
and rename.sh is your script.
I tried changing dir by putting directory names instead of the * but got
strange results.
The grand finale, which is actually what I am after, is outputing the list
of all the (now correct) filenames, to a file, reading the filenames and,
at last, be able to read the contents !!
So, how do I introduce these changes ? Must be trivial I know.
So ,recapping :
dir_name==dir1,dir2,....,dirN
call system("source rename.sh "//dir_name)
this corrects the file names of all files in all N dirs. Then these file
names are ls'd to a file so they can be read by fortran to be used.
Thanks for your help.
G.
> f="CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340)
> [SEC=UNCLASSIFIED]260.txt" echo "${f//[^[:alnum:].]}"
>
> will produce
>
> CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.txt
>
> Use a loop to iterate over all files in a directory and rename them...
>
> for f in *
> do
> mv -i "$f" "${f//[^[:alnum:].]}"
> done
>
> Hope that helps.
>
> Janis
>
>>
>> (and then I simply ls the dir into a file, read those file names and open
>> them normally since there are no nasty chars)
>>
>> so the equivalent to
>> cp CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340)
>> [SEC=UNCLASSIFIED]260.txt
>> CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TXT
>>
>> which would be done by :
>> cp "CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340)
>> [SEC=UNCLASSIFIED]260.txt"
>> CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TXT
>>
>> which cannot be done through fortran's call system for the reason above.
>>
>> (assuming no limit on filename length)
>> Specifying those unwanted chars is no problem since there aren't that
>> many.
>>
>> Thank you for any help here. I am s t u c k !
>>
>> G
Re: Problem using non-standard filenames
am 29.10.2007 12:02:52 von Janis Papanagnou
GT wrote:
>>Again, I don't understand what role your Fortran code plays.
>
>
> The details are not important, the main thing is that it is a process that
> is going to be controlled by the fortran code. This of course does not
> concern you, I had merely wished to illustrate the process.
>
>
>>Rename files and create a list of filenames in a file....
>>
>> for f in *
>> do
>> mv -i "$f" "${f//[^[:alnum:].]}"
>> echo "${f//[^[:alnum:].]}"
>> done > file_with_new_filenames
>
>
> Thank you, I understand the idea, and vaguely the code. However, here,
> according to my tests, this assume the file whose names are to be treated
> are in the same dir as the shell code above.
>
> What I tried doing, based on your shell code is expand this to fit my
> process, and so far I am not getting it right.
> This shell code is to be used with 3 arguments :
> 1 - the directory the files whose names are to be treated are in = dir1
> 2 - the name of the file that will contain the treated names
> ("file_with_new_filenames" here) = treated_data_name (this is a char, not a
> hard-coded name)
> 3 - the directory the file created in 2 is going to be in. = dir2
>
>
> So, if the shell code is called rename.sh, the idea is to invoke it like :
>
> rename.sh dir1 dir2 treated_data_name
>
> So, question is : how to adapt your shell code to invoke it like this ?
> I tried various possibilities, no luck.
>
> I hope this is clearer.
Yes, it is. So one the part of my original suggetion to switch into
many directories
for d in dir1 dir2 dir3 dirN
do (
cd "$d"
whatever-to-do-in-directory ###
)
done
can be reduced to a simple cd dir1 and the output of the other part
that you quoted above will have to use file paths instead of a file
name. If you have a call syntax as shown above the variables dir1 dir2
treated_data_name will be accessed inside the script as $1 $2 and $3
respectively. The resulting program code is...
cd "$1"
for f in *
do
mv -i "$f" "$2"/"${f//[^[:alnum:].]}"
echo "${f//[^[:alnum:].]}"
done > "$2"/"$3"
The output file will be created in the target directory dir2, so that
it will not be overwritten if you call the script multiple times for
more than one directory. This code is untested; if you have problems
feel free to ask.
Janis
>
> Thank you.
>
>
>>>>Hope that helps.
>>>>
>>>>Janis
>>>>
>>>>
>>>>
>>>>>(and then I simply ls the dir into a file, read those file names and
>>>>>open them normally since there are no nasty chars)
>>>>>
>>>>>so the equivalent to
>>>>>cp CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340)
>>>>>[SEC=UNCLASSIFIED]260.txt
>>>>>CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TX T
>>>>>
>>>>>which would be done by :
>>>>>cp "CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340)
>>>>>[SEC=UNCLASSIFIED]260.txt"
>>>>>CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TX T
>>>>>
>>>>>which cannot be done through fortran's call system for the reason above.
>>>>>
>>>>>(assuming no limit on filename length)
>>>>>Specifying those unwanted chars is no problem since there aren't that
>>>>>many.
>>>>>
>>>>>Thank you for any help here. I am s t u c k !
>>>>>
>>>>>G
>>>
>>>
>
Re: Problem using non-standard filenames
am 29.10.2007 12:36:10 von GT
> Again, I don't understand what role your Fortran code plays.
The details are not important, the main thing is that it is a process that
is going to be controlled by the fortran code. This of course does not
concern you, I had merely wished to illustrate the process.
>
> Rename files and create a list of filenames in a file....
>
> for f in *
> do
> mv -i "$f" "${f//[^[:alnum:].]}"
> echo "${f//[^[:alnum:].]}"
> done > file_with_new_filenames
Thank you, I understand the idea, and vaguely the code. However, here,
according to my tests, this assume the file whose names are to be treated
are in the same dir as the shell code above.
What I tried doing, based on your shell code is expand this to fit my
process, and so far I am not getting it right.
This shell code is to be used with 3 arguments :
1 - the directory the files whose names are to be treated are in = dir1
2 - the name of the file that will contain the treated names
("file_with_new_filenames" here) = treated_data_name (this is a char, not a
hard-coded name)
3 - the directory the file created in 2 is going to be in. = dir2
So, if the shell code is called rename.sh, the idea is to invoke it like :
rename.sh dir1 dir2 treated_data_name
So, question is : how to adapt your shell code to invoke it like this ?
I tried various possibilities, no luck.
I hope this is clearer.
Thank you.
>
>>>
>>>Hope that helps.
>>>
>>>Janis
>>>
>>>
>>>>(and then I simply ls the dir into a file, read those file names and
>>>>open them normally since there are no nasty chars)
>>>>
>>>>so the equivalent to
>>>>cp CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340)
>>>>[SEC=UNCLASSIFIED]260.txt
>>>>CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TXT
>>>>
>>>>which would be done by :
>>>>cp "CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340)
>>>>[SEC=UNCLASSIFIED]260.txt"
>>>>CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.TXT
>>>>
>>>>which cannot be done through fortran's call system for the reason above.
>>>>
>>>>(assuming no limit on filename length)
>>>>Specifying those unwanted chars is no problem since there aren't that
>>>>many.
>>>>
>>>>Thank you for any help here. I am s t u c k !
>>>>
>>>>G
>>
>>
Re: Problem using non-standard filenames
am 29.10.2007 13:50:11 von Janis Papanagnou
GT wrote:
>>>What I tried doing, based on your shell code is expand this to fit my
>>>process, and so far I am not getting it right.
>>>This shell code is to be used with 3 arguments :
>>>1 - the directory the files whose names are to be treated are in = dir1
>>>2 - the name of the file that will contain the treated names
>>>("file_with_new_filenames" here) = treated_data_name (this is a char, not
>>>a hard-coded name)
>>>3 - the directory the file created in 2 is going to be in. = dir2
>>>
>>>
>>>So, if the shell code is called rename.sh, the idea is to invoke it like
>>>:
>>>
>>>rename.sh dir1 dir2 treated_data_name
>>>
>>
>> cd "$1"
>> for f in *
>> do
>> mv -i "$f" "$2"/"${f//[^[:alnum:].]}"
>> echo "${f//[^[:alnum:].]}"
>> done > "$2"/"$3"
>>
>>The output file will be created in the target directory dir2, so that
>>it will not be overwritten if you call the script multiple times for
>>more than one directory. This code is untested; if you have problems
>>feel free to ask.
>
>
> Right,
> My dir tree is :
> subtest : contains names of files
> results : will contain corrected.txt
>
> $1=dir1=subtest
> $2=dir2=results
> $3=corrected.txt
>
> so,
> source rename.sh subtest results corrected.txt
>
> should read files in subtest, correct them and output to corrected.txt,
> newly created file in results.
> I believe this is what the script does, and if it is, it is correct.
>
> But nothing changes and I get
> bash: results/corrected.txt: No such file or directory
Right. The cd will put you in the source directory, and if the target
directory is based on the original path (i.e. not relative to the
source directory) it won't find it. So in this case redirect output
to
...
done > "$OLDPWD"/"$2"/"$3"
(OLDPWD is a bash builtin variable.)
Janis
>
> Any ideas ? Thanks.
>
>
>>Janis
>>
>>
>>>Thank you.
>>>
>>>
>>>
>>>>>>Hope that helps.
>>>>>>
>>>>>>Janis
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>(and then I simply ls the dir into a file, read those file names and
>>>>>>>open them normally since there are no nasty chars)
>>>>>>>
>>>>>>>so the equivalent to
>>>>>>>cp CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340)
>>>>>>>[SEC=UNCLASSIFIED]260.txt
>>>>>>>CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260. TXT
>>>>>>>
>>>>>>>which would be done by :
>>>>>>>cp "CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340)
>>>>>>>[SEC=UNCLASSIFIED]260.txt"
>>>>>>>CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260. TXT
>>>>>>>
>>>>>>>which cannot be done through fortran's call system for the reason
>>>>>>>above.
>>>>>>>
>>>>>>>(assuming no limit on filename length)
>>>>>>>Specifying those unwanted chars is no problem since there aren't that
>>>>>>>many.
>>>>>>>
>>>>>>>Thank you for any help here. I am s t u c k !
>>>>>>>
>>>>>>>G
>>>>>
>>>>>
>
Re: Problem using non-standard filenames
am 29.10.2007 14:17:11 von GT
>>
>> What I tried doing, based on your shell code is expand this to fit my
>> process, and so far I am not getting it right.
>> This shell code is to be used with 3 arguments :
>> 1 - the directory the files whose names are to be treated are in = dir1
>> 2 - the name of the file that will contain the treated names
>> ("file_with_new_filenames" here) = treated_data_name (this is a char, not
>> a hard-coded name)
>> 3 - the directory the file created in 2 is going to be in. = dir2
>>
>>
>> So, if the shell code is called rename.sh, the idea is to invoke it like
>> :
>>
>> rename.sh dir1 dir2 treated_data_name
>>
> cd "$1"
> for f in *
> do
> mv -i "$f" "$2"/"${f//[^[:alnum:].]}"
> echo "${f//[^[:alnum:].]}"
> done > "$2"/"$3"
>
> The output file will be created in the target directory dir2, so that
> it will not be overwritten if you call the script multiple times for
> more than one directory. This code is untested; if you have problems
> feel free to ask.
Right,
My dir tree is :
subtest : contains names of files
results : will contain corrected.txt
$1=dir1=subtest
$2=dir2=results
$3=corrected.txt
so,
source rename.sh subtest results corrected.txt
should read files in subtest, correct them and output to corrected.txt,
newly created file in results.
I believe this is what the script does, and if it is, it is correct.
But nothing changes and I get
bash: results/corrected.txt: No such file or directory
Any ideas ? Thanks.
>
> Janis
>
>>
>> Thank you.
>>
>>
>>>>>Hope that helps.
>>>>>
>>>>>Janis
>>>>>
>>>>>
>>>>>
>>>>>>(and then I simply ls the dir into a file, read those file names and
>>>>>>open them normally since there are no nasty chars)
>>>>>>
>>>>>>so the equivalent to
>>>>>>cp CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340)
>>>>>>[SEC=UNCLASSIFIED]260.txt
>>>>>>CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.T XT
>>>>>>
>>>>>>which would be done by :
>>>>>>cp "CSIRO TOPCON GPS DATA (LAB AUS, CLOCK 36 340)
>>>>>>[SEC=UNCLASSIFIED]260.txt"
>>>>>>CSIROTOPCONGPSDATALABAUSCLOCK36340SECUNCLASSIFIED260.T XT
>>>>>>
>>>>>>which cannot be done through fortran's call system for the reason
>>>>>>above.
>>>>>>
>>>>>>(assuming no limit on filename length)
>>>>>>Specifying those unwanted chars is no problem since there aren't that
>>>>>>many.
>>>>>>
>>>>>>Thank you for any help here. I am s t u c k !
>>>>>>
>>>>>>G
>>>>
>>>>
>>
Re: Problem using non-standard filenames
am 29.10.2007 15:05:22 von GT
> Right. The cd will put you in the source directory, and if the target
> directory is based on the original path (i.e. not relative to the
> source directory) it won't find it. So in this case redirect output
> to
> ...
> done > "$OLDPWD"/"$2"/"$3"
>
> (OLDPWD is a bash builtin variable.)
Yes thank you, I had "patched" it the hard way with a "../", but this is
obviously better.
This seems to work for now, time to put the theory to the test thank you
very much for your valuable help for now.
G.
>
> Janis
>
>>
>> Any ideas ? Thanks.
>>
>>
>>>Janis
>>>
>>>
>>>>Thank you.
>>>>