Reputation: 455
I have a pretty basic script that echos local administrator accounts. My goal is to get rid of all of the header/footer information.
So far I have:
FOR /F "skip=6" %%G IN ('net localgroup administrators') DO echo %%G
Which echos:
Administrator
MyName
The
"The" being the first word in the footer: "The command completed successfully."
So I'd like to get rid of "The" but I understand that I may have to restructure the entire script, which is fine. I have tried saving to a variable %str% but you can't set multi-line variables. Also, using a txt file as a buffer is not an option.
Any input?
Upvotes: 4
Views: 5523
Reputation: 130819
I can think of two simple solutions:
FOR /F "skip=6" %%G IN ('net localgroup administrators') DO if %%G neq The echo %%G
or
FOR /F "skip=6" %%G IN ('net localgroup administrators ^| findstr /vb The') DO echo %%G
I suppose one could argue a user name could be "The", in which case you can be more precise with the filter:
FOR /F "skip=6" %%G IN ('net localgroup administrators ^| findstr /vc:"The command completed successfully."') DO echo %%G
Upvotes: 6