Multicriteria search with Notepad

Solved
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

3 réponses

jee pee Posted messages 31910 Registration date   Status Modérateur Last intervention   9 947
 
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),
^(CAR,)((?!BLUE).)*$
identifies car lines EXCEPT blue and allows us to replace the line with
AUTO,GREY
but 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
^#AR
with
CAR
.

Best regards
(*) if anyone has a solution ....
1
Jack80
 
Thank you Jee Pee, it works perfectly.
0
Anonymous user
 
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.
1
ARTUROK
 
Hi,
or a script like
https://supersonique-studio.com/2009/07/rechercher-et-remplacer-en-ligne-de-commande-bash-shell-sed/
where any programming language can do that (see regular expressions).
Otherwise, not really related to a text editor or even web mastering...
0
georges97 Posted messages 14504 Registration date   Status Contributeur Last intervention   2 894
 
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
0
jee pee Posted messages 31910 Registration date   Status Modérateur Last intervention   9 947
 
Yes, as I wrote, a spreadsheet or a database could do the trick. And there you also need to know the software, its syntax, its commands.
0