I am trying to use sed to grab file path, line number, compiler warning number and warning message but I am failing.
grep -E "C6001|C6011|C28197" release-log.txt |
head |
sed -r 's/^([a-zA-Z\\:.]+)\(([0-9]+)\) warning (C[0-9]+): (.+).(.+)$/(\3) \1:\2 \4/g'
C:\WindowsFabric\src\prod\ktl\src\inc\kallocator.h(196): warning C6011: Dereferencing NULL pointer 'Allocator'. : Lines: 189, 196 [C:\WindowsFabric\src\prod\src\Lease\KTransport\user\KTransport.user.vcxproj]
C:\WindowsFabric\src\prod\ktl\src\inc\kstringview.proto.h(2505): warning C6001: Using uninitialized memory '*Temp_value_#2479'.: Lines: 2493, 2492, 2496, 2505, 2506, 2505 [C:\WindowsFabric\src\prod\src\Lease\KTransport\user\KTransport.user.vcxproj]
C:\WindowsFabric\src\prod\ktl\src\inc\kstringview.proto.h(2505): warning C6001: Using uninitialized memory '*Temp_value_#2937'.: Lines: 2493, 2492, 2496, 2505, 2506, 2505 [C:\WindowsFabric\src\prod\src\Lease\KTransport\user\KTransport.user.vcxproj]
C:\.tools\CxCache\gmock.1.11.0\lib\native\src\gtest\src\gtest-port.cc(1003): warning C6011: Dereferencing NULL pointer 'regex'. See line 996 for an earlier location where this can occur: Lines: 985, 986, 990, 991, 996, 1000, 1001, 1003 [C:\WindowsFabric\src\prod\test\GoogleTest\lib\GoogleTest.vcxproj]
C:\.tools\CxCache\gmock.1.11.0\lib\native\src\gtest\src\gtest-port.cc(1004): warning C6011: Dereferencing NULL pointer 'buffer'. : Lines: 985, 986, 990, 991, 996, 1000, 1001, 1003, 1004 [C:\WindowsFabric\src\prod\test\GoogleTest\lib\GoogleTest.vcxproj]
C:\WindowsFabric\src\prod\ktl\src\inc\ktask.h(445): warning C6001: Using uninitialized memory 'ResultSet'.: Lines: 439, 444, 445 [C:\WindowsFabric\src\prod\src\Lease\KTransport\user\KTransport.user.vcxproj]
C:\WindowsFabric\src\prod\ktl\src\inc\kallocator.h(196): warning C6011: Dereferencing NULL pointer 'Allocator'. : Lines: 189, 196 [C:\WindowsFabric\src\prod\src\ktllogger\sys\tools\GetMBInfo\GetMBInfo.vcxproj]
C:\WindowsFabric\src\prod\ktl\src\inc\kstringview.proto.h(2505): warning C6001: Using uninitialized memory '*Temp_value_#2479'.: Lines: 2493, 2492, 2496, 2505, 2506, 2505 [C:\WindowsFabric\src\prod\src\ktllogger\sys\tools\GetMBInfo\GetMBInfo.vcxproj]
C:\WindowsFabric\src\prod\ktl\src\inc\kstringview.proto.h(2505): warning C6001: Using uninitialized memory '*Temp_value_#2937'.: Lines: 2493, 2492, 2496, 2505, 2506, 2505 [C:\WindowsFabric\src\prod\src\ktllogger\sys\tools\GetMBInfo\GetMBInfo.vcxproj]
C:\WindowsFabric\src\prod\ktl\src\inc\ktask.h(445): warning C6001: Using uninitialized memory 'ResultSet'.: Lines: 439, 444, 445 [C:\WindowsFabric\src\prod\src\ktllogger\sys\tools\GetMBInfo\GetMBInfo.vcxproj
For example, given:
C:\WindowsFabric\src\prod\ktl\src\inc\kallocator.h(196): warning C6011: Dereferencing NULL pointer 'Allocator'. : Lines: 189, 196 [C:\WindowsFabric\src\prod\src\Lease\KTransport\user\KTransport.user.vcxproj]
I want:
(C6011) C:\WindowsFabric\src\prod\ktl\src\inc\kallocator.h:196 Dereferencing NULL pointer 'Allocator'
This job
is much easier with awk
. You may use:
awk -F ': ' -v OFS='\t' '{sub(/.* /, "", $2); print "(" $2 ")", $1, $3}' release-log.txt
(C6011) C:\WindowsFabric\src\prod\ktl\src\inc\kallocator.h(196) Dereferencing NULL pointer 'Allocator'.