diff --git a/Labb8/testing_sedawk/README.md b/Labb8/testing_sedawk/README.md new file mode 100644 index 0000000..d773865 --- /dev/null +++ b/Labb8/testing_sedawk/README.md @@ -0,0 +1,4 @@ +# Sed & Awk tests # +Most of these examples are from lab 8 and the book (chapter 18, Linux Command Line and +Shell Scripting Bible, 2nd edition). + diff --git a/Labb8/testing_sedawk/file.txt b/Labb8/testing_sedawk/file.txt new file mode 100644 index 0000000..01d8f47 --- /dev/null +++ b/Labb8/testing_sedawk/file.txt @@ -0,0 +1,10 @@ +Den första raden +Den andra raden +Många rader kan det bli +Långa rader också +Kanske en rad till +Varför inte ta ett par rader till +I matematiken kan vi räkna ut radius +Eller var det någon annan rad? +Det här är iaf den sista raden i en +text om rader. diff --git a/Labb8/testing_sedawk/notes.md b/Labb8/testing_sedawk/notes.md new file mode 100644 index 0000000..609c939 --- /dev/null +++ b/Labb8/testing_sedawk/notes.md @@ -0,0 +1,4 @@ +# Misc notes on sed & awk # + +sed -n '/^[MmLl]ånga/p' file.txt +sed 's/^/Spock -- /g' file.txt diff --git a/Misc/accountinfo.sh b/Misc/accountinfo.sh new file mode 100755 index 0000000..e95d70e --- /dev/null +++ b/Misc/accountinfo.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Jack-Benny Persson +# LX13 +# Testing out the IFS (Field Separator) variable +# and some sed along the way. +# Turned out to become a small script to display your account information + +# Binaries +Sed="/bin/sed" + +# Sanity check +if [ ! -x $Sed ]; then + echo "Can't execute $Sed" + exit 1 +fi + +# Set the field seprator to match that of the passwd file +IFS=$":" + +# Read the users info from the passwd file +Row=`sed -n "/$USER/p" /etc/passwd` + +# Define an array with explanitory info +Info=("Username:" "Password:" "UID:" "GID:" "Comment:" "Home:" "Shell:") + +echo "Your account information" +echo "------------------------" +# Itterate the fields and print the info +Index=0 +for i in $Row; do + echo "${Info[$Index]} $i" + ((Index++)) +done + +exit 0 + diff --git a/Misc/allaccounts.sh b/Misc/allaccounts.sh new file mode 100755 index 0000000..75d49be --- /dev/null +++ b/Misc/allaccounts.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Jack-Benny Persson +# LX13 +# Testing out the IFS (Field Separator) variable +# and some sed along the way. +# Turned out to become a small script to display your account information + +# Binaries +Sed="/bin/sed" + +# Sanity check +if [ ! -x $Sed ]; then + echo "Can't execute $Sed" + exit 1 +fi + +for entry in `cat /etc/passwd`; do + echo "Information on user `echo $entry | awk '{ print $1 }'`" + echo "---------------------------" + + IFS=$":" + Info=("Username:" "Password:" "UID:" "GID:" "Comment:" "Home:" "Shell:") + + # Itterate the fields and print the info + Index=0 + for i in $entry; do + echo "${Info[$Index]} $i" + ((Index++)) + done + echo "" +done + +exit 0 + diff --git a/Misc/itsatrap.sh b/Misc/itsatrap.sh new file mode 100755 index 0000000..38f4430 --- /dev/null +++ b/Misc/itsatrap.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Jack-Benny Persson +# LX13 +# Testing out traps + +trap "echo ' I have just trapped CTRL+C'" SIGINT SIGTERM +trap "echo ' Dont stop me plz'" SIGTSTP +trap "echo ' Ok, just exit'" EXIT + +for (( i=60; i>=0; i-- )); do + echo $i + sleep 1 +done + +exit 0 diff --git a/Misc/nesting_loops.sh b/Misc/nesting_loops.sh new file mode 100755 index 0000000..1349f93 --- /dev/null +++ b/Misc/nesting_loops.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Jack-Benny Persson +# LX13 +# Testing out nested loop from the book + +for (( a = 1; a <= 3; a++ )); do + echo "Outer loop: $a" + for (( b = 1; b <= 3; b++ )); do + echo " Inner loop: $b" + done +done + +exit 0