Given the following CSV file (filename.txt
):
1a|b|123
2a|b|123
3|4
5.7|4
66
67
10|11
11|aaa
we can determine the number 67 using:
awk -f s.awk filename.txt
where s.awk
is:
BEGIN {
FS="|"
}
NF>=1 {
q=$1
gsub(/([^[:digit:]])|([[:blank:][:punct:]])*/,"",q)
if (q==(prev+1))
if (q>max)
max=q
prev=q
}
END {
print "Max=" max
}
Update
A one-liner could look like:
awk 'BEGIN { FS="|" } { q=$1; gsub(/([^[:digit:]])|([[:blank:][:punct:]])*/,"",q); if (q==(prev+1)) {if (q>max) max=q} prev=q } END { print "Max=" max }' filename.txt