I have a question regarding findstr which I hope someone can assist with.
I would like to perform a search piped from "net user" which can search for number of strings in the output. Those strings can be specific words or and specific phase.
Specific words are not a problem and works a treat but when combined with a specific phase the results are not as expected.
Below is a extract of the command which is pulling a variable from a for loop (%%a).
2>NUL net user /domain "%%a" | FINDSTR /I /C:"2221" /C:"deprovisioned" /C:"disabled" /C:"Account active No"
FINDSTR /I "2221" "deprovisioned" "disabled" works no problem.
But I need a 4th string added at the end which unfortunately contains lots spaces.
When added the 4th search string it's simply missed from the search results.
Can anyone provide any advice?
I've converted to Powershell and problem solved.
Thank you for your input.
skothk
Related
I'm making a program that changes coordinate values in a .gcd file, i got the single coordinate lines working but the lines with double coordinates aren't. The program is supposed to split the double coordinates up and run them separately as single coordinates. To accomplish this, I sort the form the coordinates could be in to different sections of code to give the right output. Using the length of the string I can sort them easily. While programming this I ran into a simple problem of a
IF " " LEQ " " ()
command. Given values it gets the wrong outcome. A good example is:
#echo off
:start
if "14" LEQ "7" goto next
echo this should be printed
pause
exit /b
:next
echo this shouldn't be printed
pause
exit /b
Removing the " " seems to fix the issue, but I need to compare variables, which can have spaces, justifying the parenthesis. So the question is:
Why does the interpreter get to the wrong outcome, and how can I easily fix this?
Thanks, -Tom
if "14" LEQ "7" goto next
This does a lexicographic string comparison, where "14" < "7" because the first non-equal character 1 < 7.
As you noted, if you drop the quotes the following will do a numerical comparison.
if 14 LEQ 7 goto next
This is consistent with the if /? help:
These comparisons are generic, in that if both string1 and string2 are both comprised of all numeric digits, then the strings are converted to numbers and a numeric comparison is performed.
The quote (which is part of the strings being compared in the first case) is not a numeric digit, so no conversion to numbers is performed, and the comparison is done on the strings by lexical rules.
You also say that but I need to compare variables, which can have spaces. However a numeric value does/can not contain spaces and does not require quotes. On the contrary, once enclosed in quotes it's no longer a numeric value, but a string. So you'll have to decide/distinguish in advance whether you want to compare numerical vs. string values.
I am using FINDSTR -I to find a string in n number of files in a folder. Also write the results to a new file.
I need find string "IDC" along with number next to it in all files.
but on some lines in files, IDC is spread across two lines, and my search returns just first line.
09:49:34.386 4;**IDC-200.0**;CA
13:07:39.987 87;T22.8,BT2;LI;VLT12.7;**IDC-**
13:07:39.995 **42.0**;CAP240.0/
can some one help in copy next line to output file, if IDC is spread across two lines.
Microsoft’s findstr works strictly line based. It is not really possible to search for a string which does not completely exist within a line and get all lines output.
But it is possible to define multiple search strings which are used one after the other on a line before processing next line until either one of the search strings returns a positive match or none of the search strings matches a string on current line.
Example:
%SystemRoot%\System32\findstr.exe /R /C:"IDC-" /C:"^[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\.[0-9][0-9][0-9] \*\*[0-9][0-9.]*\*\*;" *.txt
Findstr (SS64 article) searches with those options in all *.txt files of current folder for
a line containing case sensitive the string IDC- anywhere within the line or
a line starting with time in expected format, a space, two asterisks, a floating point number with at least 1 digit before decimal point, two more asterisks and a semicolon.
With those two search strings all 3 lines of provided example are found and output in correct order and other lines not containing IDC- or matching the second regular expression search string are ignored by FINDSTR.
Note: SS64 article FINDSTR - Searching across Line Breaks explains how a search can be done which includes a line break. But output is nevertheless only the first line on which the found multi-line string begins.
Essentially I need to search for a word which can end and start with different things but always contains the same content in the middle.
i.e. 345345hello356
a0a0aphello553
I need to search through the registry for this key under:
HKCU\Software\[KeyBeingLookedFor]
So essentially, get the batch file to look through every key in HKCU\Sotware and if it finds it, spit out Key found via Echo.
In dos, when I wanted to get a list of files matching a specific filter, I could use something along the lines of:
*.* - Means return everything
*.txt - Means return all files with a .txt extension
*_abc.* - Means return every file that ends with _abc
My question is, using that dos filter structure, how could I return all files NOT matching *_abc.* (In other words, return all files whos name does NOT end in _abc)?
I don't remember if this is possible and I need this since a company I'm working with is using a very old program that still uses that form of command filtering for selecting files for the program to work on - Also, unfortunately, I can't do it via a batch command... It has to be a single command line statement.
Thanks!!!
Pipe the results of your listing to FINDSTR with an appropriate regex search string and the /V option to filter out matching lines.
dir /b /a-d * | findstr /v /r "_abc\.[^.]*$"
Take a look at this answer to a sort of unrelated question. The answer does show though how to do a REGEX search on file names, and of course if you use a REGEX you can easily search for things that don't match the expression.
https://stackoverflow.com/a/7381962/1246574
Hope that helps.
EDIT
Sorry, didn't see you needed it to be a single line statement and not a batch. I'll leave the above answer though in case it helps anyone else, and I'll also see if I can look up how to do it in a single statement.
Why does calling FindFirstFile with the pattern *.* match a name like Windows?
Edit: I guess I can also guess what's happening, but is there any documentation on the reason as well?
In the blog post 'How did wildcards work in MS-DOS?' Raymond Chen describes how the original DOS wildcard matching was implemented. At the end of the post he points out how *.* is handled as a special case in the Win32 wildcard matching algorithm.
A quote from the post
For example, if your pattern ends in .*, the .* is ignored. Without this rule, the pattern *.* would match only files that contained a dot, which would break probably 90% of all the batch files on the planet, as well as everybody's muscle memory, since everybody running Windows NT 3.1 grew up in a world where *.* meant all files.
*.* matches everything in the target directory.
This is because *. matches up to the final period; if there is no period in the name then that name is treated as if it ended in a period; so *. matches only names beginning with a period and names containing no period (.afile / adirname) if you add a * on the end for *.* then it also matches beyond the final period so includes file names containing a period, this covers all possible file names.