Skip to content
Advertisement

Validating file records shell script

I have a file with content as follows and want to validate the content as

1.I have entries of rec$NUM and this field should be repeated 7 times only. for example I have rec1.any_attribute this rec1 should come only 7 times in whole file.

2.I need validating script for this. If records for rec$NUM are less than 7 or Greater than 7 script should report that record.

FILE IS AS FOLLOWS :::

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=

Please Help

Thanks in Advance… 🙂

Advertisement

Answer

Simple awk:

awk -F: '/^rec/{a[$1]++}END{for(t in a){if(a[t]!=7){print "Some error for record: " t}}}' test.rc
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement