Skip to content

Commit

Permalink
[uf-select] fix invocation with multiple inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
zwets committed Jan 24, 2020
1 parent adb1254 commit ed758a1
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions uf-select
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,25 @@ fi

# Do the work

if [ -n "$NTH" ]; then
#awk -b -O -v NTH=$NTH 'BEGIN { split(NTH,lines,/,/) } int((NR+1)/2) in lines' "$@"
awk -b -O -v NTH=$NTH '
BEGIN { split(NTH,lines,/,/) }
{ for (x in lines) if (int((NR+1)/2) == lines[x]) print }
' "$@"
elif [ -n "$SEQID" ]; then
awk -b -O -v SEQID="$SEQID" '
NR % 2 == 1 && (P=index($1,SEQID)) != 0 { C=substr($1,P+length(SEQID),1); if (C=="" || C==" " || C=="|") { print; getline; print } }
' "$@"
elif [ -n "$REGEX" ]; then
awk -b -O '
NR % 2 == 1 && /'$REGEX'/ { print; getline; print }
' "$@"
else
usage_exit
fi
while [ $# -ne 0 ]; do
if [ -n "$NTH" ]; then
#awk -b -O -v NTH=$NTH 'BEGIN { split(NTH,lines,/,/) } int((NR+1)/2) in lines' "$@"
awk -b -O -v NTH=$NTH '
BEGIN { split(NTH,lines,/,/) }
{ for (x in lines) if (int((NR+1)/2) == lines[x]) print }
' "$1"
elif [ -n "$SEQID" ]; then
awk -b -O -v SEQID="$SEQID" '
NR % 2 == 1 && (P=index($1,SEQID)) != 0 { C=substr($1,P+length(SEQID),1); if (C=="" || C==" " || C=="|") { print; getline; print } }
' "$1"
elif [ -n "$REGEX" ]; then
awk -b -O '
NR % 2 == 1 && /'$REGEX'/ { print; getline; print }
' "$1"
else
usage_exit
fi
shift
done

# vim: sts=4:sw=4:et:si:ai

0 comments on commit ed758a1

Please sign in to comment.