Page 1 of 1

Search for string in file

PostPosted: Thu Dec 06, 2012 4:24 pm
by Wrangler
I'm looking for a plugin that will search for an EXACT MATCH and/or CASE SENSITIVE to a string in a file and return the line number. hpwlinenumber handles the case sensitive, but I can't find one that will do both.

Anyone know of one?

Re: Search for string in file

PostPosted: Thu Dec 06, 2012 6:51 pm
by Tony Kroos
FIND [/V or /C][/I][/N] "string" [drive:][path]filename
where:
/V Displays all lines not containing the string specified.
/C Displays the count of lines containing the string.
/I Ignores the case of characters when searching for the string.
/N Displays the line numbers with the displayed lines.

"string" Specifies the text string to find.
drive:\path Specifies the location of the file or files to search.
filename Specifies the name of the file to be searched.

p.s: some magic to copy cpnsole output directly to clipboard...
Run "cmd.exe" "/c find /n [#34]String[#34] [#34]c:\file.txt[#34] | clip" "Wait+Hidden" "" ""
... and "plugin" is ready.

Re: Search for string in file

PostPosted: Thu Dec 06, 2012 11:06 pm
by HPW
Hello,

To understand the problem: What does hpwlinenumber not?

Regards

Re: Search for string in file

PostPosted: Fri Dec 07, 2012 9:08 am
by Wrangler
Hi Hans-Peter,

hpwlinenumber doesn't have an option for an EXACT MATCH. For example, if the file contains strings, one per line, and one of the strings is 'mywebsite 1'. I want it to find ONLY 'mywebsite 1' and NOT 'mywebsite'. In other words search for the entire string in the line. The case sensitive option works well. Is it possible for you to add this option?

Re: Search for string in file

PostPosted: Fri Dec 07, 2012 12:36 pm
by HPW
Hm,

I would have thought that when you search for 'mywebsite 1' that it would only find the exact match.
I have to look into the source and to test myself.

Regards

Re: Search for string in file

PostPosted: Fri Dec 07, 2012 12:38 pm
by Wrangler
Thanks, Hans-Peter!

Re: Search for string in file

PostPosted: Fri Dec 07, 2012 1:34 pm
by HPW
I added 'mywebsite' to line 11 of my Fruitlst.txt sample file and 'mywebsite 1' to line 22.
When I use hpwLineNumber on variable or file I get 11 when I search for 'mywebsite' and 22 when I search for 'mywebsite 1'.
Just as I would expect. In fact it only supports the exact match (besides the case feature). What do you different?

Regards

Re: Search for string in file

PostPosted: Fri Dec 07, 2012 2:03 pm
by Wrangler
Thanks for checking. The problem seems to come when the string has 3 words or more. First I added 'web site 1' to file. Now I want to add a string 'web'. I want to make sure that the string 'web' is not contained on any line in file so I search for it. The plug returns the line number 'web site 1' is located.

Re: Search for string in file

PostPosted: Fri Dec 07, 2012 2:48 pm
by HPW
I do not get the logik.
When you search for web the return of the line number of web site 1 is correct, since the line contains the word.
That the way hpwLineNumber was designed.
You seems to want only the line which has only the one word.

You may use this for that:

Code: Select all
hpwLineNumber "[FruitLst1]" "[NumberStr][#13]" "True" "[LNumb]"


Note the [#13] behind the variable.

Regards

Re: Search for string in file

PostPosted: Fri Dec 07, 2012 2:53 pm
by Wrangler
That's got it! And it still works for strings with more than one word. :)

Thanks much for your help, Hans-Peter.