2

This is on Windows 7 using command line and batch files.

I was looking to examine my program list and uninstall a good amount of junk and update a good amount of outdated programs. I used a wmic command to get a text document with every program, line-by-line. I want to remove every program from that list with "microsoft", "windows", or "visual" in the name. I'm trying to do this using the findstr command, and the /v option that makes it output only lines without a match. However, running the program I wrote finds no matches within the file so basically just copies it. I tried the wild characters as well in case it's the other characters around the word messing it up or something.

Here's an example of one of the lines in the file it's looking through: (LASTNAME-LAPTOP,Microsoft Office Excel Viewer,12.0.6612.1000)

The PATH is just a representation of the path to my flash drive folder, in the script it's the actual path to a folder with both RTF files inside it. It contained a space so I put quotes around the source and output.

Here is my program:

findstr /i /v ".microsoft. .windows. .visual." "E:\PATH\programs.rtf" > "E:\PATH\programs2.rtf"
1

Running the program I wrote finds no matches within the file

I used a wmic command to get a text document with every program, line-by-line.

From wmic:

All output files are unicode text (convert to ASCII with TYPE)

This confuses findstr which expects ASCII as input, for example:

F:\test>findstr /i /v "microsoft windows visual" unicode.txt
 ■N a m e                                                                                                                       V e r s i o n

 V A I O   D a t a   R e s t o r e   T o o l                                                                                   1 . 6 . 0 . 1 3 1 4 0
 I n k s c a p e   0 . 9 1                                                                                                     0 . 9 1
 M S X M L   4 . 0   S P 3   P a r s e r   ( K B 2 7 5 8 6 9 4 )                                                               4 . 3 0 . 2 1 1 7 . 0

You can get around this using the following sequence of example commands:

wmic product get name,version > unicode.txt
type unicode.txt > programs.txt
findstr /i /v "microsoft windows visual" programs.txt > programs2.txt

Alternatively:

wmic product get name,version > programs.txt
type programs.txt | findstr /i /v "microsoft windows visual" > programs2.txt

Notes:

  • Use plain text files (not RTF) as input to findstr.
  • type is used to convert from Unicode to ASCII.
  • The . characters are not need in the findstr command

Further Reading

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.