From 9c137d4a179b38f7187e296ae3b0303f5e479c60 Mon Sep 17 00:00:00 2001 From: Steph Enders Date: Sun, 26 Feb 2023 22:06:40 -0500 Subject: Support splitting files with --- / added tests Added some tests to verify that you can now split your files with --- to join multiple queries into a single file. This could be for if you have two separate regexes to run or even two sources you want to run the same query against. Example file: ```example.conf query=.*example.conf$ source=/path/to/example/ target=/path/to/dest/ --- query=.*different.csv$ soruce=/path/to/different/ target=/path/to/dest/ ``` --- automv.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'automv.sh') diff --git a/automv.sh b/automv.sh index c5d496a..2c71375 100755 --- a/automv.sh +++ b/automv.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +TMPDIR=$(mktemp -d) +CSPLIT_PREFIX=$TMPDIR/split + if [[ -n "$AUTOMV_DIR" ]]; then automvdir=$AUTOMV_DIR else @@ -28,8 +31,24 @@ function automv { | xargs -I '{}' mv -v {} $target/ } +function split { + file=$1 + filename=$(basename --suffix=.conf $file) + csplit $1 \ + --prefix="${CSPLIT_PREFIX}-${filename}" \ + --suffix-format='_%04d.conf' \ + --elide-empty-files \ + --suppress-matched \ + --keep-files \ + /---/ '{*}' +} + echo "Executing automv functions from $automvdir" for file in $automvdir/*.conf +do + split $file +done +for file in $TMPDIR/*.conf do echo "found $file" if [[ -f $file ]]; then @@ -41,3 +60,7 @@ do automv $query $sourced $target fi done +echo "Automoved files" +echo "Removing tmp dir: $TMPDIR" +rm -r $TMPDIR +echo "Done" -- cgit v1.2.3-54-g00ecf