Skip to content

Commit

Permalink
Add optimisation options to (g)awk invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
zwets committed Jan 26, 2016
1 parent 0677a22 commit 8c77323
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions uf
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ while [ $# -ne 0 -a "$(expr "$1" : '\(.\).*')" = "-" ]; do
done

if [ -n "$REVERT" ]; then
awk -v WIDTH=80 '
/^>/ { print }
gawk -b -O -v WIDTH=80 '
/^>/
/^[^>]/ { for (i=1;i<=length();i+=WIDTH) { print substr($0,i,WIDTH); } }' "$@"
else
awk 'BEGIN { ORS="" }
gawk -b -O 'BEGIN { ORS="" }
/^>/ { if (NR!=1) print "\n"; print $0 "\n" }
/^[^>]/ { print gensub(/[[:space:]]/,"","g") }
END { print "\n" }' "$@"
Expand Down
2 changes: 1 addition & 1 deletion uf-bare
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ while [ $# -ne 0 -a "$(expr "$1" : '\(.\).*')" = "-" ]; do
shift
done

awk 'NR%2==0'
awk -b -O 'NR%2==0'

2 changes: 1 addition & 1 deletion uf-hdrs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ while [ $# -ne 0 -a "$(expr "$1" : '\(.\).*')" = "-" ]; do
shift
done

awk 'NR%2==1'
awk -b -O 'NR%2==1'

2 changes: 1 addition & 1 deletion uf-map
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ shift

# AWK it

awk "NR%2==1 { print }; NR%2==0 { print | \"$OPERATION\" }"
awk -b -O "NR%2==1 { print }; NR%2==0 { print | \"$OPERATION\" }"

44 changes: 22 additions & 22 deletions uf-valid
Original file line number Diff line number Diff line change
Expand Up @@ -157,26 +157,26 @@ done

# Do the work

awk -v P="$(basename "$0")" -v WRONG="[^$ALLOW]" -v H=$VAL_HEADERS -v Q=$QUIET -v K=$KEEP_ERRORS -v S=$STOP_ON_ERR -v IGNORECASE=$IGNORE_CASE '
{ ERR = 0
if ( H && $0 !~ /^>[[:alpha:]]+\|\w+(\|\w+)*(\s+.*)?$/ ) {
print P ": invalid header at line " NR ": " $0 > "/dev/stderr"
ERR = 1
}
HDR = $0
getline SEQ
#POS = SEQ ~ WRONG
POS = match (SEQ, WRONG)
if ( POS ) {
print P ": invalid character in sequence at line " NR ", pos " POS ": " substr(SEQ,POS,1) > "/dev/stderr"
ERR = 1
}
if ( (!ERR || K) && !Q ) {
print HDR
print SEQ
}
if ( ERR && S ) {
exit 1
}
}' "$@"
awk -b -O -v P="$(basename "$0")" -v WRONG="[^$ALLOW]" -v H=$VAL_HEADERS -v Q=$QUIET -v K=$KEEP_ERRORS -v S=$STOP_ON_ERR -v IGNORECASE=$IGNORE_CASE '{
ERR = 0
if ( H && $0 !~ /^>[[:alpha:]]+\|\w+(\|\w+)*(\s+.*)?$/ ) {
print P ": invalid header at line " NR ": " $0 > "/dev/stderr"
ERR = 1
}
HDR = $0
getline SEQ
#POS = SEQ ~ WRONG
POS = match (SEQ, WRONG)
if ( POS ) {
print P ": invalid character in sequence at line " NR ", pos " POS ": " substr(SEQ,POS,1) > "/dev/stderr"
ERR = 1
}
if ( (!ERR || K) && !Q ) {
print HDR
print SEQ
}
if ( ERR && S ) {
exit 1
}
}' "$@"

0 comments on commit 8c77323

Please sign in to comment.