[英]Using awk, how can I save records to another file if the condition below doesn't meet?
How can I save records to another file if the condition below doesn't meet. 如果不满足以下条件,如何将记录保存到另一个文件中。 I only have "if" below, i do not know where to put else condition.
我下面只有“如果”,我不知道在哪里放置其他条件。
awk '
NF {
data = substr ($0, 1, 14)
data2 = substr ($0, 1, 1)
count = gsub (/0/, "", data)
}
{if (count<=11 || data2!=5) print }' $FILES > ${DST}/${FILES}
You can do the redirection inside awk
script. 您可以在
awk
脚本中进行重定向。 Call your bash
variables from awk
by using the -v
construct. 使用
-v
构造从awk
调用bash
变量。 FILENAME
is awk
built-in variable that holds the name of the file which it will receive from ${FILES}
variable during run-time. FILENAME
是awk
内置变量,用于保存在运行时将从${FILES}
变量接收的文件名。
awk -v dst="${DST}" -v dstb="${DST_B}" '
NF {
data = substr ($0, 1, 14)
data2 = substr ($0, 1, 1)
count = gsub (/0/, "", data)
if (count<=11 || data2!=5) {
print > ( dst "/" FILENAME )
}
else {
print > ( dstb "/" FILENAME )
}
}' $FILES
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.