From 00a869ff07fea586c962abb2d630dd8e16a67a87 Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Thu, 8 Jul 2021 10:17:29 +0200 Subject: [PATCH] properly check markers of single file/all files in directory --- shell/check_markers.sh | 50 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/shell/check_markers.sh b/shell/check_markers.sh index f595321..9c9accb 100755 --- a/shell/check_markers.sh +++ b/shell/check_markers.sh @@ -1,12 +1,50 @@ ##!/bin/bash/ -dir=$1 +fildir=$1 -#ls ${dir} | while read fn; do echo $fn; cat ${dir}$fn | grep -a "|[A-Z][A-Z]," -o | wc -l; done; +if [ -z "${fildir}" ]; then + echo "CLI argument missing: provide file or directory" >&2 + exit 1 +fi -#ls ${dir} | while read fn; do echo $fn; cat ${dir}$fn | grep -a "|[A-Z][A-Z]," -o; done; +list-markers() +{ + arg="$1" + if [ -z "${arg}" ]; then + echo "list-markers: missing file argument" >&2 + exit 1 + else + if [ -d "${arg}" ]; then + echo "list-markers: file argument is a directory" >&2 + exit 1 + fi + fi + + echo -e "\n${arg}\n" + mrks=$(cat ${arg} | grep -a "|[A-Z][a-zA-Z]," -o) + mrksnum=$(echo "${mrks}" | wc -l) + echo -e "(${mrksnum})\n${mrks}" +} -#ls ${dir} | while read fn; do echo $fn; cat ${dir}$fn | xxd | head -n10 | tail -n3; done; +if [ -f "${fildir}" ]; then + + echo "analyzing single file ${fildir} ..." + list-markers "${fildir}" + +elif [ -d "${fildir}" ]; then + + echo "analyzing all *.raw files in directory ${fildir} ..." + lsfls=$(ls ${fildir}/*.raw | sed 's/\/\//\//g') + echo -e "\n${lsfls}" + + for fl in ${lsfls}; do + list-markers "${fl}" + done + +else + + echo "does not exist: ${fildir}" >&2 + exit 1 + +fi -ls ${dir} | while read fn; do echo $fn; cat ${dir}$fn | grep -a "|[A-Z][a-zA-Z]," -o | wc -l; done; -ls ${dir} | while read fn; do echo $fn; cat ${dir}$fn | grep -a "|[A-Z][a-zA-Z]," -o; done;