I was wondering if it's possible to use findstr and/or gawk to return the output of a windows cmd exactly how I need it to be. I'm currently returning the output raw, then stripping out the blank lines, and parsing out what I need. Just as a learning thing, I was hoping I could see how this can be done better.
The raw output:
Change 2086888 on 2012/01/23 by user1@server1
test_description_1.2.3.4@29816
Change 2086888 on 2012/01/23 by user1@server2
test_description2_4.5.6.7@29816
Change 2078677 on 2012/01/20 by user2@server1
test_description3_7.8.9.10@29816
I take that output and parse it out to this with php:
1. 2086888,test_description_1.2.3.4@29816
2. 2086888,test_description2_4.5.6.7@29816
3. 2078677,test_description3_7.8.9.10@29816
To make it a little easier on myself, I remove the blank lines from the output by piping it to findstr and using /V "^$". So it's | findstr /V "^$".
How can I get the output that I parse out with php directly from the command line?
for
command in cmd.exe skips blank lines, so it may be easier to parse it this way:
@Echo Off
setlocal enabledelayedexpansion
set linenum=1
for /f "tokens=1,2" %%A in (output.txt) do @(
if %%A==Change set result=%%B
if not %%A==Change (
echo !linenum!. !result!,%%A
set /a linenum=!linenum!+1
)
)
endlocal