создал программу, которая проверяет CSV-файл по заданным параметрам.однако эффективность пошла на спад, когда я добавил ограничение на число символов с помощью регулярных выражений
awk -F, '
BEGIN { FPAT = "([^,]+)|(\"[^\"]+\")" }
NF!=17 { print "incorrect amount of fields-OFFFENCE FILE"; next}
#splits the line up into 17 seperate fields when encountering a comma,
#however ignores commas located within double quotes and then assigns each field to a varible to be checked later.
#then counts the amount of fields if more or less than 17 prints message.
!($1~/^("[A-Z0-9]{1,25}")$/) {print "1st field invalid-OFFENCE FILE";}
#check the data contained within varible 1 that in this case has only uppercase letters and numbers and consists of
#between 1 and 25 characters and that it also begins and ends with a double quote
!($2~/("[[:digit:]]{1,3}")$/) {print "2nd field invalid-OFFENCE FILE";}
!($3~/^("[A-Z0-9]{1,8}")$/) {print "3rd field invalid-OFFENCE FILE";}
!($4~/^("[A-Z0-9]{0,1}")$/) {print "4th field invalid-OFFENCE FILE";}
!($5~/^("[A-Z0-9]{0,11}")$/) {print "5th field invalid-OFFENCE FILE";}
!($6~/^("")$/) {print "6th field invalid-OFFENCE FILE";}
!($7~/^("[0-9]{4}[-/][0-9]{2}[-/][0-9]{2}")$/B) {print "7th field invalid-OFFENCE FILE";}
!($8~/^("[1-5]{1}")$/) {print "8th field invalid-OFFENCE FILE";}
!($9~/^("[0-9]{4}[-/][0-9]{2}[-/][0-9]{2}")$/) {print "9th field invalid-OFFENCE FILE";}
!($10~/^("[0-9]{4}[-/][0-9]{2}[-/][0-9]{2}")$/) {print "10th field invalid-OFFENCE FILE";}
# the validation above checks for dates in the format #YYYY-MM-DD with either a - or a / as a seperator
!($11~/^("([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]")|""$/) {print "11th field invalid-OFFENCE FILE";}
#the regex above tests for times to make sure they meet the format of hh:mm:ss
!($12~/^("([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]")|""$/) {print "12th field invalid-OFFENCE FILE";}
!($13~/^("[A-Za-z0-9]{0,70}")|""$/) {print "13th field invalid-OFFENCE FILE";}
!($14~/^("[A-Za-z0-9]{1}")|""$/) {print "14th field invalid-OFFENCE FILE";}
!($15~/^("[0-9]{3}")$/) {print "15th field invalid-OFFENCE FILE";}
!($16~/^(".+{1,2500}")$/) {print "16th field invalid-OFFENCE FILE";}
!($17~/^(".+{1,4000}")|""$/) {print "17th field invalid-OFFENCE FILE";}
{print "previous field set correct_OFFENCE FILE "}' nppcase_***_******_offence_**************.csv
, поэтому мой вопрос, есть ли способ повысить эффективность.
ps пример не имеет значения, егонеэффективно ли переменная заполнена или пуста в принципе, я хочу, чтобы код работал намного быстрее, и проблема в том, что максимальная длина символа в регулярном выражении $ 16 и $ 17 слишком высока