我想在 awk 中设置一个变量,该变量由附加三个包含文件名的字符串组成。该命令应该打印 numbera
和之间的行b
。
find "$dir" \( -name \*.org -o -name \*.texi \) \
-exec awk -v a="$na" -v b="$nb" \
-v red="$(tput setaf 1)" \
-v nrm="$(tput sgr0)" \
-v rd="\033[1;31m" \
-v nr="\033[0m" \
's = "==>" FILENAME "<=="
FNR == 1 {f = 0}
FNR == a {print red, s, nrm; f = 1}
f {print; if (FNR == b) nextfile}' {} +
答案1
你有s = ...
awk 语法的条件部分condition {action}
。看起来应该将其移至FNR == 1 { ... }
操作中:
find "$dir" \( -name \*.org -o -name \*.texi \) \
-exec awk -v a="$na" -v b="$nb" \
-v red="$(tput setaf 1)" \
-v nrm="$(tput sgr0)" \
'
FNR == 1 {s = "==>" FILENAME "<=="; f = 0}
FNR == a {print red, s, nrm; f = 1}
f {print; if (FNR == b) nextfile}' {} +