summaryrefslogtreecommitdiff
path: root/os1w5
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-03-13 16:42:48 +0100
committerlonkaars <loek@pipeframe.xyz>2023-03-13 16:42:48 +0100
commit92d35a975b45fe4696be370ab68c285bbeef65f2 (patch)
tree82867a26d00c4829f7ab820c7eb5ad426b850a5c /os1w5
parent2798a8145fa7c349ac45b688ab346add765ace32 (diff)
os1 week 5 af
Diffstat (limited to 'os1w5')
-rwxr-xr-xos1w5/lettercount.sh17
-rw-r--r--os1w5/practicum.md49
-rwxr-xr-xos1w5/textfrutter.sh52
3 files changed, 118 insertions, 0 deletions
diff --git a/os1w5/lettercount.sh b/os1w5/lettercount.sh
new file mode 100755
index 0000000..9ff3436
--- /dev/null
+++ b/os1w5/lettercount.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+usage() {
+ echo "usage: $0 <file> <letter1> [letter2] [letter3] [...]"
+ exit 1
+}
+
+[[ ! -f "$1" ]] && echo "file does not exist" && usage
+[[ "$#" -lt 2 ]] && echo "not enough arguments" && usage
+
+file="$1"
+shift
+for letter in "$@"; do
+ [[ ! "${#letter}" -eq 1 ]] && echo "argument \"$letter\" too long" && usage
+ echo "$letter -> `cat $file | tr -cd $letter | wc -c`"
+done
+
diff --git a/os1w5/practicum.md b/os1w5/practicum.md
new file mode 100644
index 0000000..5b463a9
--- /dev/null
+++ b/os1w5/practicum.md
@@ -0,0 +1,49 @@
+# practicum week 5
+
+## 1
+
+```bash
+find ~
+```
+
+## 2
+
+```bash
+find ~ -type f
+```
+
+## 3
+
+```bash
+find . -type f -mtime 1
+```
+
+## 4
+
+```bash
+find . -type f -exec wc -l {} \; | awk '$1 > 5 { print $2 }'
+```
+
+## 5
+
+```bash
+$ ./textfrutter.sh -l -p "volgende argument is: " -v Bob Koen Bart
+volgende argument is: bb
+volgende argument is: kn
+volgende argument is: brt
+```
+
+## 6
+
+```bash
+$ ./lettercount.sh practicum.md a e u i o
+a -> 12
+e -> 23
+u -> 6
+i -> 11
+o -> 6
+$ ./lettercount.sh practicum.md
+not enough arguments
+usage: ./lettercount.sh <file> <letter1> [letter2] [letter3] [...]
+$
+```
diff --git a/os1w5/textfrutter.sh b/os1w5/textfrutter.sh
new file mode 100755
index 0000000..8c8ffe3
--- /dev/null
+++ b/os1w5/textfrutter.sh
@@ -0,0 +1,52 @@
+#!/bin/dash
+TO_UPPER=""
+TO_LOWER=""
+PREFIX=
+SUFFIX=
+FILTER_VOWELS=""
+ARGC=0
+
+usage() {
+ cat << EOF
+usage: $0 [-luvh] [-p prefix] [-s suffix] [inputs...]
+
+options:
+ -l convert inputs to lowercase
+ -u convert inputs to uppercase
+ -v remove vowels from inputs
+ -h show help
+ -p prefix add \`prefix\` to each line before inputs
+ -s suffix add \`suffix\` to each line after inputs
+
+notes:
+ if -l and -u are specified at the same time, the lowercase option will have
+ precedence
+EOF
+ exit $1
+}
+
+while getopts dulhp:s:v OPT; do
+ [ $OPTIND -gt $ARGC ] && ARGC=$OPTIND
+ case $OPT in
+ u) TO_UPPER="y" ;;
+ l) TO_LOWER="y" ;;
+ h) usage 0 ;;
+ p) PREFIX=$OPTARG ;;
+ s) SUFFIX=$OPTARG ;;
+ v) FILTER_VOWELS="y" ;;
+ \?|*) usage 1 ;;
+ esac
+done
+
+[ $(( $# - $ARGC )) -lt 0 ] && echo "please provide some input" && usage 1
+
+shift $(( ARGC - 1 ))
+
+while [ -n "$1" ]; do
+ OUT="$1"
+ [ -n "$TO_UPPER" ] && OUT="`echo "$OUT" | sed 's/./\U\0/g'`"
+ [ -n "$TO_LOWER" ] && OUT="`echo "$OUT" | sed 's/./\L\0/g'`"
+ [ -n "$FILTER_VOWELS" ] && OUT="`echo "$OUT" | sed 's/[aeuio]//g'`"
+ echo "$PREFIX$OUT$SUFFIX"
+ shift
+done