diff --git a/carlpett-awfulShell/Day07A-death_by_pipe.sh b/carlpett-awfulShell/Day07A-death_by_pipe.sh new file mode 100755 index 00000000..e87d4bba --- /dev/null +++ b/carlpett-awfulShell/Day07A-death_by_pipe.sh @@ -0,0 +1,9 @@ +#!/bin/bash +cat $1 | \ + tr -dc [:alpha:][:space:] | \ + sed -r 's/ +/\n/g' | \ + grep -vE '^ *$' | \ + sort | \ + uniq -c | \ + grep -E '^ +1 ' | \ + sed -r 's/ +1 //' diff --git a/carlpett-awfulShell/Day07A-grep_only.sh b/carlpett-awfulShell/Day07A-grep_only.sh new file mode 100755 index 00000000..dea74583 --- /dev/null +++ b/carlpett-awfulShell/Day07A-grep_only.sh @@ -0,0 +1,8 @@ +#!/bin/bash +cur=$(grep -- '->' $1) +while [[ $? -eq 0 ]]; do + cur=${cur/ */} + next=$cur + cur=$(grep $cur $1 | grep -vE "^$cur") +done +echo $next diff --git a/carlpett-awfulShell/Day08-sed_codegen.sh b/carlpett-awfulShell/Day08-sed_codegen.sh new file mode 100755 index 00000000..5f2346e2 --- /dev/null +++ b/carlpett-awfulShell/Day08-sed_codegen.sh @@ -0,0 +1,10 @@ +#!/bin/bash +max=0 +declare -A vars=() +eval $(cat $1 | sed -r 's/inc/+/; s/dec/-/; s/([a-z]+) ([+-]) ([-0-9]+)/vars[\1]=$((${vars[\1]-0} \2 \3)); if [[ ${vars[\1]-0} -gt $max ]]; then max=${vars[\1]}; fi/; s/^(.+) if ([a-z]+) ([!=<>]+) ([-0-9]+)/if [[ $(echo "${vars[\2]-0} \3 \4" | bc) -eq 1 ]]; then \1; fi;/') +for v in "${!vars[@]}" +do + echo $v=${vars["$v"]} +done | +sort -rn -t= -k2 | head -n1 +echo $max \ No newline at end of file diff --git a/carlpett-awfulShell/README.md b/carlpett-awfulShell/README.md new file mode 100644 index 00000000..25a99b4c --- /dev/null +++ b/carlpett-awfulShell/README.md @@ -0,0 +1,5 @@ +# Awful shell solutions +Some days, you just want to pipe + +## Running +The scripts take the path to the input file as first and only parameter