Hello guys i am having problem printing out the exact line in a string. I have tried using the /x parameter but its not working so i need some help...thanks!
Codes below
findstr /x "SeNetworkLogonRight=*S-1-1-0IUSR_SEANAdministrators" C:\user_rights.txt
Try: findstr /x "SeNetworkLogonRight=\*S-1-1-0IUSR_SEANAdministrators"or
findstr /x /l "SeNetworkLogonRight=*S-1-1-0IUSR_SEANAdministrators"It's strange that a full wildcard (zero or more characters of anything) would cause the problem, but it seems to....
edit:
I just remembered that "." is the wild card and "*" is the repeat for findstr, so it makes perfect sense...
hmm it doesnt work..i have problem with the /x operator. I have tried creating a simple text file containing the word "hello" inside.
But when i do findstr /x "hello" C:\hi.txt it doesnt show me anything..whats wrong man?
"/x" does mean the whole line, including any spaces, tabs or any other character..... Do you have absolutely anything else on the line?
Are there any other unexpected attributes to this file? (such as being a unix lf only vs a dos/windows crlf).
Other than that I tested with xp's findstr, it could have been changed with windows 7....
im doing this operation on a windows xp inside a virtual machine..i have tried it on windows 7 too but i cant get the /x operator to work.I am very sure i type the exact string..
The two searches work fine for me(with a file name appended) so I'm not sure what to say......
Is it possible the text file is not ansi encoded, perhaps unicode? Findstr doesn't seem to like unicode, I haven't tried with other formats....edit
Can you upload the text file somewhere like megaupload of mediafire?
Thank you, that made it fairly plain what the problem is!
Findstr doesn't seem to like to to find lines with "/x"(or /e) if they don't end in a line break.
D:\Downloads>findstr /x "computer" hi.txt D:\Downloads>findstr /b /e "computer" "hi.txt" D:\Downloads>findstr /b "computer" "hi.txt" computer D:\Downloads>type hi.txt | findstr /x "computer" computer D:\Downloads>echo.>>hi.txt D:\Downloads>findstr /x "computer" hi.txt computer D:\Downloads>findstr /b /e "computer" "hi.txt" computer D:\Downloads>The solution is simple, either add a line break to the end of the file/line or use a command like type that will add one automatically.
type file.txt | findstr /x "search-string"or
>> file.txt echo. findstr /x "search-string" file.txt
yay i tried type file.txt | findstr /x "search-string" and it works! Thanks alot dude thats some valuable information i learnt up there
argh i just cant seem to retrieve the exact string out of this line in the file below..
i have tried using type C:\nospace.txt | findstr /x "SeBackupPrivilege=AdministratorsBackupOperators"
It won't match because there's a trailing space on every
line in nospace.txt.
findstr /x /c:"SeBackupPrivilege=AdministratorsBackupOperators "
that works:) thanks..i have learnt a lot from you!
Partly out of curiosity, what is it that generated that file
(nospace.txt)? If it's one of your batch scripts, you're
probably echoing lines like this:echo sometext >> fileIf you lose the space between 'sometext' and '>>'...
echo sometext>> fileyou won't get the trailing spaces in the file which may
save you any frustration/nasty surprises in the future.
@MarkLS echo sometext>> file
That leaves an issue if the last character on the line is a number and the second last a space(mimicking stream redirection):echo something no 2>> Somefile >> somefile echo something no 2The same can happen with %variables%.
Its safer to redirect before echo, but if you know exactly what your dealing with and it's not affected then it doesn't matter.
That leaves an issue if the last character on the line is a number and the second last a space(mimicking stream redirection) That's interesting. Hadn't considered that before - just
thought it was some kind of personal preference which
looked kind of confusing. (Some of you 'long-termers'
in here seem to really know your stuff!)Thanks for the heads up!
hey sorry to trouble you guys but can i ask is there anyway to filter out only the BUILTIN\Administrator line and its atttributes to a text file? The constraint is that the file permissions are dynamic so i couldn't number the lines and filter them out.. Sample file
http://www.mediafire.com/?2emuzt1kp...
Obviously, the solution is to get better output.
hey sorry to trouble you guys but can i ask
is there anyway to filter out only the
BUILTIN\Administrator line and its atttributes
to a text file?You can try the code below. Not sure if it's ultimately what
you want though. Did you check out the link that Razor
posted in Response # 17? How does that change things?EDIT: I've just noticed that, although the code works
here on the file that you uploaded,
if you edit it in the slightest way, it all goes
pear-shaped. Not sure what's going on there,
can't figure it out, but probably best that you
give it a miss :)@echo off setlocal EnableDelayedExpansion set InFile=hi1.txt set OutFile=out.txt type nul> "%OutFile%" for /f "tokens=1 delims=:" %%a in ('findstr /n /c:"BUILTIN\Administrators:(special access:)" "%InFile%"') do set DataStart=%%a for /f "tokens=1 delims=:" %%a in ('findstr /r /n /c:"^[ ]*$" "%InFile%"') do ( set DataEnd=%%a if !DataEnd! gtr %DataStart% goto LineNumbersDone ) :LineNumbersDone for /f "tokens=1* delims=:" %%a in ('findstr /r /n ".*" "%InFile%"') do ( if %%a geq %DataStart% if %%a lss %DataEnd% echo %%b>> "%OutFile%" )
The logic is to find the line numbers where the data
starts and ends, using a blank line or - as it is in this
case - a line with only spaces to mark the end of
the data, then print out the lines in that range.
Filenames are set to hi1.txt (which is what you
posted) for input and out.txt for the output.
OK, I found more time to figure out what the probable
cause of the trouble was (re: my Response #18). The
file that you uploaded has a strange mixture of CR, CRLFs
for line breaks. You definitely need better output ;)
Sorry for bumping this topic, but i just want to say i have used another alternative suggested by Razor...and thank you everyone for helping me!
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |