Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 验证文件记录shell脚本_Linux_Bash_Shell_Unix_Sh - Fatal编程技术网

Linux 验证文件记录shell脚本

Linux 验证文件记录shell脚本,linux,bash,shell,unix,sh,Linux,Bash,Shell,Unix,Sh,我有一个文件,内容如下,并希望验证内容如下 1.我有rec$NUM的条目,该字段只能重复7次。 例如,我有rec1.any_属性,这个rec1在整个文件中应该只出现7次 2.我需要为此验证脚本。 如果rec$NUM的记录小于7或大于7,脚本应报告该记录。 文件如下::: rec1:sourcefile.name= rec1:mapfile.name= rec1:outputfile.name= rec1:logfile.name= rec1:sourcefile.nodename_col

我有一个文件,内容如下,并希望验证内容如下

1.我有rec$NUM的条目,该字段只能重复7次。 例如,我有rec1.any_属性,这个rec1在整个文件中应该只出现7次

2.我需要为此验证脚本。 如果rec$NUM的记录小于7或大于7,脚本应报告该记录。

文件如下:::

rec1:sourcefile.name=

rec1:mapfile.name=

rec1:outputfile.name=

rec1:logfile.name=

rec1:sourcefile.nodename_col=

rec1:sourcefle.snmpnode_col=

rec1:mapfile.enc=

rec2:sourcefile.name=abc

rec2:mapfile.name=

rec2:outputfile.name=

rec2:logfile.name=

rec2:sourcefile.nodename_col=

rec2:sourcefle.snmpnode_col=

rec2:mapfile.enc=

rec3:sourcefile.name=abc

rec3:mapfile.name=

rec3:outputfile.name=

rec3:logfile.name=

rec3:sourcefile.nodename_col=

rec3:sourcefle.snmpnode_col=

rec3:mapfile.enc=
请帮忙

提前感谢……:)


以上所有内容都应返回7。

Simple
awk

awk -F: '/^rec/{a[$1]++}END{for(t in a){if(a[t]!=7){print "Some error for record: " t}}}' test.rc
命令:

grep rec file2.txt | cut -d':' -f1 | uniq  -c | egrep -v '^ *7'
如果文件符合您的规则,则会成功;如果文件不符合您的规则,则会失败(并返回失败记录)


(如果记录编号可以混合,则将“uniq-c”替换为“sort-u”。

对不起,如果一个文件中有1000条记录,我将如何处理每个记录
grep rec file2.txt | cut -d':' -f1 | uniq  -c | egrep -v '^ *7'