I need to parse a file and grab certain fields from it using a regular expression as part of the delimiter. I thought I can use perl to do this(?). The problem is I can’t get it to work properly. Here’s a one liner which I thought would allow me to print fields that are separated by one more white spaces (in this case one or more space):
bash_prompt> perl -anF'/ +/' -e 'print "$F[0], $F[-1]\n"' build_outputfile
The output file is from a makefile.
Here, I want to print out the first token, and the last token. So in my case which compiler was used and which file was compiled. Perhaps there’s a better way to do it, but now I’m bothered as to why my perl one liner does not work.
Anyways, the regular expression ‘/ +/ does not appear to work. I get some unexpected output. Perhaps F does not actually want a regular expression? When I replace F’s argument with ‘/ /’ that contains one space, I still don’t get a expected output.
Can anyone help? Thanks.
Here’s some test code for you to try. Save it in a file:
g++ -c -g -Wall -I/codedir/src/CanComm/include -I/home/codemonkey/workspace/thirdparty/Boost -Wno-deprecated SCMain.cpp
g++ -c -g -Wall -I./object/include -I./wrapper/include -I./Properties/include -I./Messaging/include -I/codedir/src/Logging/sclog/include ./object/SCObject.cpp ./object/RandNumGenerator.cpp ./object/ScannerConstraints.cpp ./object/ThreadSync.cpp ./object/SCData.cpp ./object/AirScanData.cpp ./object/ClusterData.cpp ./object/WarmupData.cpp ./object/SCCommand.cpp ./object/ScanCommands.cpp ./object/RCCommands.cpp ./object/ReconData.cpp ./object/UICommTool.cpp ./object/UIMsg.cpp ./object/UI2SCConversion.cpp ./object/RCMsg.cpp ./object/RCMessageInfo.cpp ./object/Utils.cpp ./object/ZBackupTable.cpp ./object/ZBackupFactory.cpp
g++ -c -g -Wall -I./Properties/include -I/codedir/src/Logging/sclog/include -I./object/include -I/home/codemonkey/workspace/thirdparty/Boost ./Properties/PropertyMap.cpp
According to
perldoc perlrun:I have to admit: What a thoroughly arbitrary restriction!