2

I am trying to find the line (or lines, in this case there is only one possible result) containing this expression tableName_tOracleOutput_1 = " in a .java file. I'm using the command findstr "tableName_tOracleOutput_. ^= /"" dt_dea_kaspersky.java directly on the cmd.exe but the output is not what I expect, as you can see:

C:\Users\miguilem\Desktop\test_folder>findstr "tableName_tOracleOutput_. ^= /""  dt_dea_kaspersky.java
                        String tableName_tOracleOutput_1 = null;
                                tableName_tOracleOutput_1 = "dt_dea_kaspersky";
                                tableName_tOracleOutput_1 = dbschema_tOracleOutput_1 + "."
                                        + tableName_tOracleOutput_1
                                                                "mo_dwh/dt_dea_kaspersky_0_1/contexts/"

This result would be nearly the same as if I omitted the double quotes at the end of the expressions (giving me results I don t really need, i just want the line that contains the double quotes after the equals and a space). This is the result of the command with omitted doublequotes that (obviously) does not grant me the single result I want

C:\Users\miguilem\Desktop\test_folder>findstr "tableName_tOracleOutput_. ^= "  dt_dea_kaspersky.java
                        String tableName_tOracleOutput_1 = null;
                                tableName_tOracleOutput_1 = "dt_dea_kaspersky";
                                tableName_tOracleOutput_1 = dbschema_tOracleOutput_1 + "."
                                        + tableName_tOracleOutput_1

(note the inconsistency of the two outputs, apparently the escaped doublequotes does not get completely ignored, they apparently cause a random additional ghost line STRAIGHT OUTTA NOWHERE, this line (mo_dwh/dt_dea_kaspersky_0_1/contexts/) is not even present in the code nor in a filename anywhere on the whole file system) I checked the newline characters with notepad++ and it looks as expected (standard CR|LF).

Besides the completely useless official documentation (which literally asks the user to go read about it somewhere else on a not linked command line guide) I checked for information here:

  1. Escaping Double Quotes in Batch Script
  2. http://www.robvanderwoude.com/findstr.php
  3. https://ss64.com/nt/findstr.html
  4. http://www.robvanderwoude.com/escapechars.php

At this point I think I missed something very basic, if you need any other information to replicate or solve the problem, don't hesitate to ask! Thanks.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Patches
  • 49
  • 1
  • 8
  • 4
    feel free to read this lengthy explanation of the `FINDSTR` command in your free time: [What are the undocumented features and limitations of the Windows FINDSTR command?](https://stackoverflow.com/questions/8844868/what-are-the-undocumented-features-and-limitations-of-the-windows-findstr-comman) – Squashman Dec 03 '18 at 15:28
  • Thanks for the link, i saw it linked in multiple sources while wondering on the FINDSTR hate train, didn't bother reading it at first cause i tought it was uselss to read about "undocumented features" implying those were "additional" features while I couldn't even use basic features out of confusion. A couple lines into it and it already looks worth the read, I suggest the link to anyone using the FINDSTR command. – Patches Dec 03 '18 at 15:38

1 Answers1

2

"tableName_tOracleOutput_. ^= /"" with no more options is interpreted as regular expression string searching case-sensitive for tableName_tOracleOutput_ with one more character matched by . OR = at beginning of a line OR a slash followed by a double quote. The space character in a double quoted search string is interpreted as OR.

The command line to use for your search task is:

findstr /R /C:"tableName_tOracleOutput_. = "" dt_dea_kaspersky.java

The option /C: is usually used for a literal search string. But in this case the string inside the double quotes is interpreted nevertheless as regular expression string because of additionally using option /R with an important difference in comparison to just "tableName_tOracleOutput_. = "": the space characters are not interpreted as OR expressions, but as literal characters.

The " at end of search string could be escaped with \, but that is not really necessary.

Mofi
  • 46,139
  • 17
  • 80
  • 143
  • Thanks boss, in the end I messed up a basic mechanic as I guessd, problem is the documentation expects you to guess what "literal" means in "/C:string Use string as a literal search string (may include spaces).". – Patches Dec 03 '18 at 15:23