Skip to content

Commit

Permalink
Want some bash?
Browse files Browse the repository at this point in the history
  • Loading branch information
carlpett committed Dec 8, 2017
1 parent 1537d69 commit a9fb9c6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions 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 //'
8 changes: 8 additions & 0 deletions 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
10 changes: 10 additions & 0 deletions 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
5 changes: 5 additions & 0 deletions 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

0 comments on commit a9fb9c6

Please sign in to comment.