Shiva wrote:
> I've lots of different file names. Not even similar ones. But say all of them are put in a single directory. And I want to change the name for all these files in this directory. Just a minor change. Like from HIJKLMNO to NEWKLMNO - to change the file names in the front, possibly - because obviously all my file names are starting in the same manner and ending differently which I would like to use to my advantage.
>
>
> I'm guessing fup rename $VOL.SUBVOL.*, $
VOL.SUBVOL.NEW* should work. Just that I'm not sure. Yes, I could rather try it, but I'm away at home, considering this be a weekend. Just let me know if this would work? Thank you. :)
No, the command you suggest will not work. In the FUP RENAME command, while you can use some general wildcarding in the source position of RENAME, the only sort of wildcarding you can use in the target position is to have a subvol or a name be a single *, which means that part of the filename is copied from the corresponding part of the source. For example, you could write
FUP RENAME $VOL.SUBVOL.ABC*,$VOL.NEWSUBVL.*
Which would rename all the files in SUBVOL that begin with ABC to be in NEWSUBVL, but their names in NEWSUBVL will be the same, beginning with ABC. Files in SUBVOL whose names did not begin with ABC will not be renamed. Or you could rename everything in a subvolume:
FUP RENAME $VOL.SUBVOL.*,$VOL.NEWSUBVL.*
You can have a wildcard in the subvolume part of the source, but if you do, the filename part must be a * by itself. The manual's description of RENAME does not make this point clear, and I might not be stating the rule completely correctly, as I am just going by my recollection of what I was able to make work from time to time in the past. I'm not sure there is any fundamental reason for that restriction on the form of the source. It might just have made the implementation easier.
But none of that is what you want to do.
There might be a one-line way to do those renames from the OSS command line. You can access and rename Guardian files from OSS, and someone advanced in the art of regular expressions could, I believe, write a regular expression that expressed the renaming you want to do, but I have a feeling you cannot use such a regular expression in an OSS mv command, the command that does renames. So I think OSS cannot come to the rescue for this case, though if someone can show how to do it in a single OSS command, I'd be interested to learn how to do it.
However, there is a way to do those renames without typing each one individually. A short TACL macro can do it. If you put the following lines into an Edit file, and for sake of discussion, let's say that file is named REN:
?tacl macro
#frame
[#push fn name newname oldprefix oldlen newprefix]
[#set oldprefix %1%]
[#set oldlen [#charcount oldprefix]]
[#set newprefix %2%]
[#set fn [#filenames/maximum 1/ [oldprefix]*]]
[#loop |while| not [#empty [fn]]
|do|
[#set name [#fileinfo/file/ [fn]]]
[#set newname [name]]
[#chardel newname 1 for oldlen]
[#charins newname 1 [newprefix]]
rename [name],[newname]
[#set fn [#filenames/maximum 1,previous [fn]/ [oldprefix]*]]
]
#unframe
then you can do the renaming you want with the following command:
RUN REN HIJ NEW
If REN is in a different subvolume than the files you want to rename, just qualify the name of REN:
RUN $VOL.SUBVOL.RUN HIJ NEW
If you put REN in a subvolume that is on your PMSEARCH list, you can dispense with the RUN and qualification:
REN HIJ NEW
The TACL code above does no error checking, so it isn't a good, robust piece of code, but for a one-time job, it is good enough. Just a brief explanation: The #filenames expression gets the files that match the prefix one at a time. The other code in the loop gets the part of the filename after the last ".", removes the old prefix, adds the new prefix, then does the rename. It only works in the current subvolume, so you have to be sure your current subvolume is the one in which you want to make the change when you run it.
TACL's programming language probably is a bit different from others you have used unless you are familiar with some other macro substitution language. It takes a little getting used to, but once past the initial learning hump, it is a fairly easy language to use, and has good facilities for controlling line-mode command interfaces. The TACL Reference Manual has the complete definition of the language and all of its built-in functions. The TACL Programming Guide is intended to help you learn to use TACL's programming language.