Multicriteria search with Notepad
Solved
Jack80
-
Jack80 -
Jack80 -
Hello,
I have a file with several hundred lines like this
CAR,CHAIR,BLUE,1234,RZC
CAR,6HP,GREEN,5478,GHF
DESK,TABLE,BLUE,8742,JUD
CAR,7HP,GREEN,2457,FDS
CAR,7HP,BLUE,3651,FDS
DESK,LAMP,BLACK,5475,HIJ
CAR,7HP,BLUE,1265,IOG
DESK,CABINET,BLACK,9875,HDS
CAR,7HP,GREEN,8574,FDR
CAR,7HP,BLACK,3655,FDY
CAR,7HP,BLUE,3651,FDS
CAR,6HP,BLUE,1234,GHP
And with Notepad, I would like to search and replace the "CAR" that are not "BLUE" with "AUTO" "GREY" while keeping all the lines.
Is that possible?
Thank you for your response
Configuration: Windows / Chrome 83.0.4103.116
I have a file with several hundred lines like this
CAR,CHAIR,BLUE,1234,RZC
CAR,6HP,GREEN,5478,GHF
DESK,TABLE,BLUE,8742,JUD
CAR,7HP,GREEN,2457,FDS
CAR,7HP,BLUE,3651,FDS
DESK,LAMP,BLACK,5475,HIJ
CAR,7HP,BLUE,1265,IOG
DESK,CABINET,BLACK,9875,HDS
CAR,7HP,GREEN,8574,FDR
CAR,7HP,BLACK,3655,FDY
CAR,7HP,BLUE,3651,FDS
CAR,6HP,BLUE,1234,GHP
And with Notepad, I would like to search and replace the "CAR" that are not "BLUE" with "AUTO" "GREY" while keeping all the lines.
Is that possible?
Thank you for your response
Configuration: Windows / Chrome 83.0.4103.116
3 réponses
Hello,
As mentioned above, creating an updated version of the file with a spreadsheet (Excel, ...) would be easy.
However, if Notepad doesn't refer to Windows' notepad but to the Notepad++ editor, we can get the job done with regular expressions.
Not in a single command, because while the EXCEPT function allows you to target a line, you can only replace it entirely, not retrieve elements (*).
Thus, with the replace function in Notepad++ (regular expression option checked),
We can then proceed in steps:
- CAR BLUE becomes #AR BLUE
replace
- CAR XXX becomes AUTO GREY
replace
- #AR BLUE becomes CAR BLUE again
replace
Best regards
(*) if anyone has a solution ....
As mentioned above, creating an updated version of the file with a spreadsheet (Excel, ...) would be easy.
However, if Notepad doesn't refer to Windows' notepad but to the Notepad++ editor, we can get the job done with regular expressions.
Not in a single command, because while the EXCEPT function allows you to target a line, you can only replace it entirely, not retrieve elements (*).
Thus, with the replace function in Notepad++ (regular expression option checked),
^(CAR,)((?!BLUE).)*$identifies car lines EXCEPT blue and allows us to replace the line with
AUTO,GREYbut does not allow us to retrieve the original information.
We can then proceed in steps:
- CAR BLUE becomes #AR BLUE
replace
^(CAR,)(.*?,)(BLUE,)(.*?,)(.*)with
#AR,\2\3\4\5.
- CAR XXX becomes AUTO GREY
replace
^(CAR,)(.*?,)(.*?,)(.*?,)(.*)with
AUTO,\2GREY,\4\5.
- #AR BLUE becomes CAR BLUE again
replace
^#ARwith
CAR.
Best regards
(*) if anyone has a solution ....
Jack80
Thank you Jee Pee, it works perfectly.
Hello
Unfortunately, Notepad ("notepad.exe") is just a text editor with a rather rudimentary Find/Replace function.
Your request for "conditional" searching is more in the realm of a spreadsheet, provided you have some familiarity with it. Commas could easily be interpreted as column separators.
See you later
--
If the answer helped or saved you: a little thank you, if it's resolved: click the green button at the top ;-)
Let him who has never opened a user manual throw the first mouse at me.
Unfortunately, Notepad ("notepad.exe") is just a text editor with a rather rudimentary Find/Replace function.
Your request for "conditional" searching is more in the realm of a spreadsheet, provided you have some familiarity with it. Commas could easily be interpreted as column separators.
See you later
--
If the answer helped or saved you: a little thank you, if it's resolved: click the green button at the top ;-)
Let him who has never opened a user manual throw the first mouse at me.
Hello everyone,
@jeepee, your solution uses combined commands capable of performing all sorting and filtering, but it "forces" you to master the syntax.
Since you're inviting us to do so, I propose to retrieve the text file in the Base software from the LibreOffice suite.
By using the functions of this database, I think we can achieve the same result by filling out a simple query, or even chaining them together using the Basic programming language.
What do you think?
Best regards
@jeepee, your solution uses combined commands capable of performing all sorting and filtering, but it "forces" you to master the syntax.
Since you're inviting us to do so, I propose to retrieve the text file in the Base software from the LibreOffice suite.
By using the functions of this database, I think we can achieve the same result by filling out a simple query, or even chaining them together using the Basic programming language.
What do you think?
Best regards