From b68dbf35ed2d4ee2fa41caff23879f0fe0ca1e31 Mon Sep 17 00:00:00 2001 From: Marco van Zwetselaar Date: Sun, 10 May 2020 03:00:59 +0300 Subject: [PATCH] [uf-select] fix stdin case without dash --- uf-select | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/uf-select b/uf-select index c554b9a..6cdbf8f 100755 --- a/uf-select +++ b/uf-select @@ -29,8 +29,8 @@ usage_exit() { echo " Usage: $(basename $0) [OPTIONS|NUMBERS|REGEX] [FILE ...] - Select sequences from unfasta FILEs and write to standard output. If no FILE - is present or when FILE is '-', read standard input. + Select sequences from unfasta FILEs and write to standard output. + If no FILE is present or when FILE is '-', read standard input. OPTIONS -n, --nth N[,..] Select the nth sequence(s) for each file. @@ -106,25 +106,24 @@ fi # Do the work -while [ $# -ne 0 ]; do +FILE="${1:--}" + +while [ -n "$FILE" ]; 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 ' + awk -b -v NTH=$NTH ' BEGIN { split(NTH,lines,/,/) } { for (x in lines) if (int((NR+1)/2) == lines[x]) print } - ' "$1" + ' "$FILE" elif [ -n "$SEQID" ]; then - awk -b -O -v SEQID="$SEQID" ' + awk -b -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" + ' "$FILE" elif [ -n "$REGEX" ]; then - awk -b -O ' - NR % 2 == 1 && /'$REGEX'/ { print; getline; print } - ' "$1" + awk -b "$(printf 'NR %% 2 == 1 && /%s/ { print; getline; print }\n' "$REGEX")" "$FILE" else usage_exit fi - shift + [ $# -gt 0 ] && shift && FILE="$1" || unset FILE done # vim: sts=4:sw=4:et:si:ai