Это можно сделать с помощью скользящего окна:
parse.awk
# Split the pattern into the `p` array and remember how many there are in `n`
BEGIN { n = split(pat, p, "\n") }
# Collect n lines into the `A` array
NR <= n { A[NR] = $0; next }
# Maintain the sliding window after n lines
NR > n {
for(i=2; i<=n; i++)
A[i-1] = A[i]
A[n] = $0
}
# Test if the current window contains the pattern
{
hit = 1
for(i=1; i<=n; i++) {
split(A[i], x)
if(x[1] != p[i]) {
hit = 0
break
}
}
# If the window matches print the second column
if(hit) {
split(A[1], x)
print x[2]
}
}
Запустите это так:
awk -v pat="$(< patternfile)" -f parse.awk infile
Выход:
253
fsid=0 для параметров монтирования в /etc/exports был одинаковым и должен отличаться. Это работает сейчас.