Replacements in dependent tiers

20 views
Skip to first unread message

remeig...@gmail.com

unread,
Jan 23, 2022, 3:06:46 PM1/23/22
to chibolts

Dear all,

We are trying to find a way to replace several codes we used in a dependent tier in many files, in order to create new files with these new codes.

As far as I know, the CHSTRING command with a .cut file containing a list of all the replacements can be used for this purpose, but I’m afraid of going wrong and replacing strings that we are not supposed to, specially in the case of complex codes containing characters like : or – (although I believe they’re not considered metacharacters in this case).

I would go with something like:

CHSTRING %dep “$code-Iwant-to-change” “resulting-code”.

Is there any other way to do it or is there any unique option I should use in the case of using CHSTRING in dependent tiers?

Furthermore, I noticed the next: when using CHSTRING command it gives me back as an output a .chstr.cex file format. Is there any way to avoid this?

Thank you in advance,

--

Remei González Manzanero 

Leonid Spektor

unread,
Jan 23, 2022, 6:01:48 PM1/23/22
to ChiBolts
Hi,

I will start with last question. The reason CHSTRING command outputs ".chstr.cex" filenames is so that you can check the output to see if changes were done correctly and nothing went wrong. If you really want to take a chance then add +1 option to the command line. Otherwise, after you verify that only right string were replaced correctly you can use command "ren -f *.chstr.cex *.cha" to change all output filenames to .cha.

For the first question CHSTRING command works on word bases by default. This means that the string that you want to replace has to completely match the code in the data file. For example, if you have codes "$code-1want-to-change" and "$code-2want-to-change", then following commands will replace only code "$code-1want-to-change":

chstring +t%dep +s"$code-1want-to-change" "$new-code"
chstring +t%dep +s"$code-1*" "$new-code*"

Please notice the "+t%dep" option. It will guarantee that only codes found on %dep tier will be replace. The same string on other tiers will not be changed.

If you want a more detailed example, then you can email your sample file to me directly along with a list of codes you want to replace and I will give you the exact command line(s).


Leonid.

--
You received this message because you are subscribed to the Google Groups "chibolts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chibolts+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chibolts/303df79e-aed9-4a00-899a-735f85d62ccfn%40googlegroups.com.

remeig...@gmail.com

unread,
Jan 25, 2022, 4:27:34 PM1/25/22
to chibolts
Good day, 
Thank you very much for the fast reply. I really appreciate your help. 

Now I understand what the +1 is for, I saw it in other commands used by other people but I didn't understand it. 

Regarding to the specific command "chstring +t%dep +s"$code-1*" "$new-code*"", using the * would keep with no changes all the words contained in that *? So would this mean that I can replace specific parts of the old codes using this specific command? 

Another question that just came to me now is that: is there any way to use exceptions in the codes, such as changing a code that contains specific words except for one word? I'm not sure if I'm expressing myself right. 

Example: chstring +t%dep +s"$code-*want-to-change-EXCEPT 'SPECIFIC-WORD-I-DON'T-WANT-TO-CHANGE" "$new-code"

Thank you for offering giving the exact command lines. I believe for now it is okay, I will practice with the command before and I will let you know in the case we need more help. 

Best regards, 
--
Remei González Manzanero

Leonid Spektor

unread,
Jan 25, 2022, 8:59:02 PM1/25/22
to ChiBolts
The strings that are matched by wild characters, like * and _, are not changed and are copied to the output. The best way to see what commands do is to try them on a small customized sample file. In regard to except words, there is no feature to do that. Except, do not include that word in search string and then search string will not match the word you want to exclude. CHSTRING allows to specify a file with different search and replace entries, so you can specify as many of those as you want. This will allow you to very specifically customize what word or part of string you want to match and which you want to exclude.


Leonid.

remeig...@gmail.com

unread,
Jan 27, 2022, 1:24:02 PM1/27/22
to chibolts
Dear Leonid, 
Fantastic. Thank you very much for all your assistance. It really helped. 
Thank you and best regards, 
Reply all
Reply to author
Forward
0 new messages