简体   繁体   English

如果不满足以下条件,如何使用awk将记录保存到另一个文件中?

[英]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. FILENAMEawk内置变量,用于保存在运行时将从${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.

相关问题 如何使用 grep 或 awk 使用一个文件从另一个文件中填充缺失的信息? - How can I use a file to fill in missing information from another file using grep or awk? 如何基于另一个文件的内容使用awk / sed删除特定行 - How can I delete specific lines using awk/sed based on the contents of another file 使用AWK或SED如何删除第一列的字符数不等于13的任何行 - Using AWK or SED how can I remove any line where the first column's character count doesn't equal 13 使用ls查找满足条件的列表文件 - List file using ls to find meet the condition 在 bash 中,如何在一个文件中找到与另一个文件的任何行都不匹配的模式? - in bash, how can I find a pattern in one file that doesn't match any line of another file? AWK脚本如果满足使用AWK命令的条件,我可以分配变量吗? - Awk script Can I assign a variable if a condition using awk command is met? Bash/Awk:如何使用 bash 或 awk 运行命令 - Bash/Awk: How can I run a command using bash or awk 当文件列包含给定范围与另一个文件之间的位置时,使用Awk和Condition来捕获行 - Using Awk and Condition for catching lines when column of a file contains a position between a given range by another file 如何使用awk解析Makefile - How can I parse the Makefile using awk 如何使用awk标记$ PATH? - How can I tokenize $PATH by using awk?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM