Last active
December 14, 2015 10:59
-
-
Save mchirico/5076097 to your computer and use it in GitHub Desktop.
Simple awk with split, variable NF and NR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example AWK script | |
# echo -e '1 2 3\n4 5 6\n10.11.12'| awk -v DATE=$(date "+%m%d%y") -f t1.awk | |
# | |
/[0-9]*\.[0-9]*\./ { n=split($1,a,"."); print n " values in s" } | |
{ | |
if (NR==1) {print $1 " Rec number: " NR " Fields " NF} | |
} | |
END {print DATE | |
for(i=1; i <= n; ++i) print "a[" i "]= " a[i] " n= " n | |
} | |
# | |
# Example output | |
# | |
# 1 Rec number: 1 Fields 3 | |
# 3 values in s | |
# 030313 | |
# a[1]= 10 n= 3 | |
# a[2]= 11 n= 3 | |
# a[3]= 12 n= 3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment