AWK-examples

AWK. computing

Grep

cat logrunAddFvTToScratchOneOffset|awk 'Aver' awk 'rchi2 || Training || Vali {print $0}' ZZ4b/nTupleAnalysis/pytorchModels/3bDvTMix4bDvT.v0.nf12FvTHCR+attention12np2076lr0.01epochs20offset0.log

Grep with watch

watch "awk 'Training || Vali {print \$0}'" ZZ4b/nTupleAnalysis/pytorchModels/3bDvTMix4bDvT.v1.nf12FvTHCR+attention12np2076lr0.01epochs20offset0.log

As an aside, it's easy to test your understanding of regular expressions interactively: the program $1 ~ $2 lets you type in a string and a regular expression; it echoes the line back if the string matches the regular expression.

Display a block of text with AWK

awk ‘/startpattern/,/stoppattern/’ file.txt

eg: cat logrunAddFvTToScratchOneOffset|awk 'Aver,/.pkl/'

awk '/ files:/,/lumis_processed/' skimmer/metadata/picoaod_datasets_declustered_data_Run3_v3_seed0.yml

replace

ls |awk 'Extended {printf("mv %s ",$0); gsub("Extended","",$0); print $0}'

System within AWK

ls /home/scratch/jalison//closureTests/ULTrig/*/*nf8* | awk '{ s=$0; gsub("nf8.h5","nf8offset0.h5"); d=$0; system(" mv "s" "d) } '

Graph

printf "width 100\n height 30 \n label x-axis " | cat trafficDeathsTEST - |awk -f graph.awk

AWK resubmitting failed condor jobs

ls -lrt logs/ |grep OTemd |grep log|grep "Sep 13"| awk '{gsub(".log",".jdl"); cmd = "condorsubmit " $9; print cmd; system(cmd) }'

Pipe AWK output into bash loop

for i in grep parallel logs/OT_emd_mat_2018_Nominal_SBToSR_nJet*stdout | grep -v FERM |awk '{gsub(":python","");gsub("stdout","jdl");gsub("logs/","");print $1};'; do condorsubmit $i; done