Refactor awk script to drop ENDFILE feature from 4.1.1

Signed-off-by: Carlos Hernandez <carlos@techbyte.ca>
pull/117/head
Carlos Hernandez 7 years ago
parent b6852910dd
commit 8760cafd36

@ -2,12 +2,30 @@
# shellcheck disable=2016
AWK_ADD_TO_GITIGNORE='
BEGIN { cnt=0; }
BEGIN {
cnt=0
}
function check_print_line(line){
if (line == pattern) {
cnt++
}
print line
}
# main function
{
print $0
if ( $0 == pattern ) cnt++;
check_print_line($0) # check and print first line
while (getline == 1) { # check and print all other
check_print_line($0)
}
}
END {
if ( cnt == 0) { # if file did not contain pattern add
print pattern
}
}
ENDFILE { if ( cnt == 0) print pattern; }
'
function gitignore_add_pattern {

Loading…
Cancel
Save