Command to filter log

We may need to send a large number of log files out of office, but those log may contains sensitive or private data.  The below command in Windows batch (tested under Windows 7)

for /r %f in (Sever*.log) do type %~nf.log | findstr /v "PrivateContent" > Filtered_%~nf.log

  1. The for /r list all files in current folder.
  2. (Server*.log) is my filter criteria.  You may change your own according to your need.  
  3. %f extract the each file name with full path
  4. %~nf extract only file name (without path and extension).
  5. | (pipe) redirect output from type command to findstr
  6. findstr /v is to filter out lines with "PrivateContent"
  7. "PrivateContent": you may change your keyword according to your need. e.g. password, account number, etc.
  8. > redirect the output to a new file.
  9. The new file will be named Filterd_ServerXXXXX.log.


Popular Posts