Find in files
-
Hi, I have hundreds of files (text files with an extension .ini) in which I would like to erase any occurence of _**** in a string. Example B_013, B_010, or A_0001 etc . After _ we have between 1 to 5 digits maximum. I know it is possible, but I do not know how to proceed. Thanks beforehand for your help.
-
FIND =
_\d{1,5}
REPLACE = <leave empty>
SEARCH MODE = Regular expressionIt means “find a literal underscore, followed by 1 to 5 digits”
----
Useful References
-
Re: Find in files
Unfortunately, it does not work.
YoursHere is an example:
ExportVersion = 19.0 [Position] |451.264751764512|-201.994864155059|219.247893699306 [Rotation] |0|0|1|180 [PannelloGrezzo] DimX|994.8400 DimY|540.0000 DimZ|19.0000 [PannelloFinito] DimX|994.8400 DimY|540.0000 DimZ|19.0000 [Pannello] DirezioneL|1.0000000000|0.0000000000|0.0000000000 NFacce|6 Faccia|0 Normale|0.0000000000|0.0000000000|1.0000000000 NElementi|4 Linea1|0.0000|540.0000|0.0000|0.0000|0.0000|0.0000 Linea2|994.8400|0.0000|0.0000|0.0000|0.0000|0.0000 Linea3|994.8400|540.0000|0.0000|994.8400|0.0000|0.0000 Linea4|994.8400|540.0000|0.0000|0.0000|540.0000|0.0000 Faccia|1 Normale|0.0000000000|-1.0000000000|0.0000000000 NElementi|4 Linea1|0.0000|0.0000|0.0000|0.0000|0.0000|-19.0000 Linea2|994.8400|0.0000|-19.0000|0.0000|0.0000|-19.0000 Linea3|994.8400|0.0000|0.0000|994.8400|0.0000|-19.0000 Linea4|994.8400|0.0000|0.0000|0.0000|0.0000|0.0000 Faccia|2 Normale|0.0000000000|0.0000000000|-1.0000000000 NElementi|4 Linea1|0.0000|0.0000|-19.0000|0.0000|540.0000|-19.0000 Linea2|994.8400|540.0000|-19.0000|0.0000|540.0000|-19.0000 Linea3|994.8400|0.0000|-19.0000|994.8400|540.0000|-19.0000 Linea4|994.8400|0.0000|-19.0000|0.0000|0.0000|-19.0000 Faccia|3 Normale|0.0000000000|1.0000000000|0.0000000000 NElementi|4 Linea1|0.0000|540.0000|-19.0000|0.0000|540.0000|0.0000 Linea2|994.8400|540.0000|0.0000|0.0000|540.0000|0.0000 Linea3|994.8400|540.0000|-19.0000|994.8400|540.0000|0.0000 Linea4|994.8400|540.0000|-19.0000|0.0000|540.0000|-19.0000 Faccia|4 Normale|1.0000000000|0.0000000000|0.0000000000 NElementi|4 Linea1|994.8400|540.0000|0.0000|994.8400|0.0000|0.0000 Linea2|994.8400|0.0000|0.0000|994.8400|0.0000|-19.0000 Linea3|994.8400|0.0000|-19.0000|994.8400|540.0000|-19.0000 Linea4|994.8400|540.0000|-19.0000|994.8400|540.0000|0.0000 Faccia|5 Normale|-1.0000000000|0.0000000000|0.0000000000 NElementi|4 Linea1|0.0000|540.0000|0.0000|0.0000|0.0000|0.0000 Linea2|0.0000|540.0000|-19.0000|0.0000|540.0000|0.0000 Linea3|0.0000|0.0000|-19.0000|0.0000|540.0000|-19.0000 Linea4|0.0000|0.0000|0.0000|0.0000|0.0000|-19.0000 [ForatureMultiple] #IShape Name :|MultiHole [5x10] [20x2] NSerieFori|8 DefForo|1|5.0000|10.0000|7.5000|2.5000|0.0000|0.0000|0.0000000000|0.0000000000|-1.0000000000|1000 Serie_1|193.4200|503.0000|-19.0000|321.4200|503.0000|-19.0000|5|32.0000 Serie_2|353.4200|503.0000|-19.0000|481.4200|503.0000|-19.0000|5|32.0000 Serie_3|513.4200|503.0000|-19.0000|641.4200|503.0000|-19.0000|5|32.0000 Serie_4|673.4200|503.0000|-19.0000|801.4200|503.0000|-19.0000|5|32.0000 Serie_5|193.4200|76.0000|-19.0000|321.4200|76.0000|-19.0000|5|32.0000 Serie_6|353.4200|76.0000|-19.0000|481.4200|76.0000|-19.0000|5|32.0000 Serie_7|513.4200|76.0000|-19.0000|641.4200|76.0000|-19.0000|5|32.0000 Serie_8|673.4200|76.0000|-19.0000|801.4200|76.0000|-19.0000|5|32.0000 [EndForatureMultiple] [ForatureSingole] [EndForatureSingole] [ForatureGeneriche] #IShape Name :|OKENOT|INGLOBA PROFILO| TipoForo_1|1 ProfForo_1|2 Foro_1|19.0000|0.0000000000|0.0000000000|-1.0000000000|0 Estrusione|0.0000000000|0.0000000000|1.0000000000| NElementi|4 PStart|782.0000|508.0000|-19.0000| Linea1|782.0000|540.0000|-19.0000| Linea2|737.0000|540.0000|-19.0000| Linea3|737.0000|508.0000|-19.0000| Linea4|782.0000|508.0000|-19.0000| [EndForatureGeneriche] [FresateMultiple] [EndFresateMultiple] [Fresate] [EndFresate] #PartName :LATERAL_1 [DATIASSEMBLAGGIO] ParteNumero| Descrizione| PathImmagine| [DATIGENERALI] ParteNumero|Kast B_008 Descrizione| OKE_ID|Kast B_010 OKE_IDCODE|Kast B_008 Num_RIP|1 Title| Project| Revision| Version| Author| State| Description| Date| CodeProduction| CodeClient| Client| [DATIAGGIUNTIVI] NElementi|38 Custom0|Border1|_ Custom1|Border2|_ Custom2|Border3|_ Custom3|Border4|_ Custom4|BorderTh1|_ Custom5|BorderTh2|_ Custom6|BorderTh3|_ Custom7|BorderTh4|_ Custom8|Category|_ Custom9|Cover1|_ Custom10|Cover1Add1|_ Custom11|Cover1Add2|_ Custom12|Cover1Total1|_ Custom13|Cover1Total2|_ Custom14|Cover2|_ Custom15|Cover2Add1|_ Custom16|Cover2Add2|_ Custom17|Cover2Total1|_ Custom18|Cover2Total2|_ Custom19|CoverTh1|_ Custom20|CoverTh2|_ Custom21|Designation|_ Custom22|Material|WS980-ST2 Custom23|MaterialCategory|WS980-ST2 Custom24|MaterialGroup|Standard Custom25|OKE_CAB_C|Kast B Custom26|OKE_CAB_ID|002 Custom27|OKE_CAB_N|LATERAL_1 Custom30|OKE_PAN_H|540 Custom31|OKE_PAN_L|994,84 Custom32|OKE_PAN_S|19 Custom33|OKE_PAN_VENA|0 Custom34|OKE_PAR_H|540 Custom35|OKE_PAR_L|994,84 Custom36|OKE_PAR_S|19 Custom37|Supplier|_ Custom38|Treatment|_ Custom39|Type|_ [DatiPannello] Materiale |WS980-ST2 Tipo Materiale |WS980-ST2 Prezzo Unitario |10 Direzione Vena |0 Scarto |0 OverDim_L |0|0 OverDim_H |0|0 OverDim_S |0|0 Unità di Misura |2 Quantità |0.5372136 Prezzo Totale |5.372136 [Impiallacciature] Impiallacciatura0|0|||0|0||0.0000000000|0.0000000000|-1.0000000000| Impiallacciatura1|0|||0|0||0.0000000000|0.0000000000|1.0000000000| [Bordature] NElementi|0 NormalePannello|1.0000000000|0.0000000000|0.0000000000 [EstrusioniImportate] [EndEstrusioniImportate] #End Of File
-
That was really annoying. There was no reason to create a new topic, when replying to this topic would work. I had to do some weird moderator stuff to be able to merge this back in to be the same topic. If you’re still talking about Find in Files, REPLY here, don’t create a NEW TOPIC!
You also ignored all the advice in the links I made about how to format a post so it’s readable, so I’ve also had to use moderator powers to reformat it.
-
@wojh8547tg said in TMPRENAME Find in files:
Unfortunately, it does not work.
Yes it does.
Before:
After:
It does exactly what you asked for: it took removed the _ followed by 1 to 5 digits.
If that’s not actually what you wanted, you will have to read the “Template for Search/Replace Questions” which I linked you to before, and ask your question better.
-
You are right. It works. Now, would it be possible to write the query in order to focus on three particular lines.
The line starting with
ParteNumero|
OKE_ID|
OKE_IDCODE|Example:
ParteNumero|Kast B_008 -> ParteNumero|Kast B
OKE_ID|Kast B_010 -> OKE_ID|Kast B
OKE_IDCODE|Kast B_008 -> OKE_IDCODE|Kast BYours.
-
FIND =
^(ParteNumero|OKE_ID|OKE_IDCODE).*\K_\d{1,5}
REPLACE WITH = <leave empty>
SEARCH MODE = Regular ExpressionIn the new stuff:
- the
^
means “line must start with what comes next”. - the
|
means “OR”, soParteNumero OR OKE_ID OR OKE_IDCODE
. - the
(
parentheses)
are for making a “group”. - the
.*
means allow anything between. - the
\K
means “start the replacement here rather than at the beginning of the match”.
So it will look for lines beginning with one of those three words, then on those lines, start the replacement at the underscore as long as the underscore is followed by exactly 1-5 digits, no more, no less.
If you have more line-start prefixes in the future, just put another
|
between the existing ones and the new one; all must stay within the parentheses. If you want to force there to be a literal|
character in there, it would have to be\|
because|
alone means Logic-OR. So^( ParteNumero\|Kast|OKE_ID|OKE_IDCODE)
would say "start withParteNumero|Kast
with a literal|
required, or start with OKE_ID or OKE_IDCODE.How specific or generic you end up making it depends on your needs.
You will need to start studying the user manual regex section to learn more about the concepts I’ve mentioned.
- the
-
Beautiful !
I just had to write it like this:
^(ParteNumero||OKE_ID||OKE_IDCODE).*\K_\d{1,5}Double || because | was part of the name.
Thanks Peter. -
@wojh8547tg said in Find in files:
I just had to write it like this:
^(ParteNumero||OKE_ID||OKE_IDCODE).*\K_\d{1,5}Double || because | was part of the name.
You apparently didn’t read my answer. Double
||
means “ParteNumero OR nothing or OKE_ID or nothing or OKE_IDCODE” Since those groups can contain “nothing”, you will once again match more than you expect to match.as I said before, if you want to match a literal
|
, you need to have\|
in your regex. I even gave you an example of how to use it, but you chose to ignore me. Good luck with that.