From 8b229ca80d3f07e935b8a13e0bcfbaf7a7dd6d64 Mon Sep 17 00:00:00 2001 From: Lewis Westbury Date: Tue, 20 Feb 2024 16:18:53 +0000 Subject: [PATCH] Add shell scripting files --- .gitignore | 3 +- shell_scripting/summarise-sln.sh | 47 ++++++++++++++++++++++++++++++++ shell_scripting/summarise.sh | 46 +++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100755 shell_scripting/summarise-sln.sh create mode 100755 shell_scripting/summarise.sh diff --git a/.gitignore b/.gitignore index 3597f5d..a55fdf5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ __pycache__/ .ipynb_checkpoints/ */data/* -*.env \ No newline at end of file +*.env +.metaflow diff --git a/shell_scripting/summarise-sln.sh b/shell_scripting/summarise-sln.sh new file mode 100755 index 0000000..60b25b1 --- /dev/null +++ b/shell_scripting/summarise-sln.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +set -e +set -o pipefail + +usage() { + cat << EOF +Summarise the files in a directory + +Options: + -i --input-directory The input directory + -h --help Prints this help message and exits + +EOF +} + +while [ -n "$1" ]; do + case $1 in + -i | --input-directory) + shift + IN_DIR=$1 + ;; + -h | --help) + usage + exit 0 + ;; + *) + echo -e "Unknown option $1...\n" + usage + exit 1 + ;; + esac + shift +done + +if [ -z "$IN_DIR" ]; then + echo "Please provide an input directory." + usage + exit 1 +fi + +for FILE in $IN_DIR/*; do + [ -f "$FILE" ] || break + BYTES=$(wc -c < "$FILE") + echo "$(file $FILE) - has: $(echo $BYTES | tr -d ' ') bytes" +done + diff --git a/shell_scripting/summarise.sh b/shell_scripting/summarise.sh new file mode 100755 index 0000000..0b3380c --- /dev/null +++ b/shell_scripting/summarise.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +set -e +set -o pipefail + +usage() { + cat << EOF +Summarise the files in a directory + +Options: + -i --input-directory The input directory + -h --help Prints this help message and exits + +EOF +} + +while [ -n "$1" ]; do + case $1 in + -i | --input-directory) + shift + IN_DIR=$1 + ;; + -h | --help) + usage + exit 0 + ;; + *) + echo -e "Unknown option $1...\n" + usage + exit 1 + ;; + esac + shift +done + +if [ -z "$IN_DIR" ]; then + echo "Please provide an input directory." + usage + exit 1 +fi + +for FILE in $IN_DIR/*; do + [ -f "$FILE" ] || break + BYTES=$(wc -c < "$FILE") + echo "$(file $FILE) - has: $BYTES bytes" +done