samiam41
asked on
Remove column in output file from batch script
Hi Experts. I'm using the following command to output a list of processes running on a computer. I wanted to remove some of the columns that are being written to the log file but wasn't sure if it could be done.
I appreciate your help with this!
pslist | findstr.exe /v /i /r /c:"^chrome\>" /c:"^sVchost\>" >> %log%
I appreciate your help with this!
ASKER
Thank you. Testing it now.
There are 8 columns in the output log file. So, using for /f to read each column as %%a, %%b, and so on.
Just remove the %%x which corresponding to the column you don't want from the echo line
Just remove the %%x which corresponding to the column you don't want from the echo line
for /f "tokens=1-8 skip=2" %%a in (c:\temp\log.txt) do (
echo %%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h >> %log%
)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@oBdA, here is what I have for the script. could you please review and see what I did wrong as all of the columns are showing up even though I modified the "set columns" option (I only pasted the top portion of the script as that's the only location containing what I added) .
@echo off
setlocal enabledelayedexpansion
set Log=c:\tools\logs\audit.log
set Columns=1 2
cls
cd\
cd tools\pstools
echo. >> %log%
echo. >> %log%
echo %date% %time: =0% >> %log%
ASKER
@tgtran, can you put together your portion of the script with what I posted, please? I'm not sure if I am putting them together correctly.
pslist | findstr.exe /v /i /r /c:"^chrome\>" /c:"^sVchost\>" >> %log%
for /f "tokens=1-8 skip=2" %%a in (c:\temp\log.txt) do (
echo %%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h >> %log%
)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@tgtran,
Using your script above, this is what log2 yields:
How do I get the columns back and make it easier to read?
Using your script above, this is what log2 yields:
Name,Time
Idle,329:07:01.747
System,329:07:01.747
smss,329:07:01.622
csrss,329:06:55.616
wininit,329:06:52.090
csrss,329:06:52.075
services,329:06:51.966
lsass,329:06:51.888
lsm,329:06:51.888
winlogon,329:06:51.201
nvvsvc,329:06:47.488
nvwmi64,329:06:47.239
nvSCPAPISvr,329:06:47.223
spoolsv,329:06:28.751
armsvc,329:06:28.236
AppleMobileDeviceService,329:06:27.986
atashost,329:06:26.738
mDNSResponder,329:06:26.613
BtSwitcherService,329:06:26.598
CsrBtOBEXService,329:06:26.239
CsrBtService,329:06:26.145
DisplayFusionService,329:06:25.677
How do I get the columns back and make it easier to read?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your time and suggestions on this question!!
oBdA's script won out as it was easier to configure the look of the output file but tgtran solution worked so I gave partial credit/points.
Again, always glad to work with experts like you all. Take care!
oBdA's script won out as it was easier to configure the look of the output file but tgtran solution worked so I gave partial credit/points.
Again, always glad to work with experts like you all. Take care!
ASKER
Anyone interested in a few more points, I would appreciate you stopping by here.
https://www.experts-exchange.com/questions/28931915/Add-content-to-output-file.html
https://www.experts-exchange.com/questions/28931915/Add-content-to-output-file.html
In line 4, you define the header you want, separated by tabs.
In line 6, you define the columns by letter, with %%a=col1, and so on.
Open in new window