inital P01 version published - Instructions are available under Moodle

This commit is contained in:
Andreas Gieriet 2020-02-15 19:57:20 +01:00
parent a7eda8d4b2
commit 2e878d8489
3 changed files with 82 additions and 0 deletions

26
P01_Bash/get-exec-list-arg.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
# produces a tabular output of all executables as found over the $PATH environment variable
# - output format: [1-based index of $PATH entry]:[$PATH entry]:[name of the executable]
# - e.g. 6:/bin:bash
# - the first argument (if given) is used as alternative to $PATH (e.g. for testing purposes)
# usage: ./get-exec-list-arg.sh # examines $PATH
# usage: ./get-exec-list-arg.sh "$PATH" # equivalent to the above call
# usage: ./get-exec-list-arg.sh ".:~/bin" # examines the current directory (.) and ~/bin
# argument handling
path="$1"
[ -n "$path" ] || path="$PATH"
# input-field-separator: tells the shell to split in the 'for' loop the $var by ":"
IFS=":"
for p in $path
do
i=$((i+1))
[ -n "$p" ] || p="."
if [ -d "$p" ] && [ -x "$p" ]
then
find -L "$p" -maxdepth 1 -type f -executable -printf "$i:%h:%f\n" 2>/dev/null
fi
done

35
P01_Bash/tab2html.sh Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash
# produces a crude HTML table from a tabular file (given on stdin) with columns separated by ":"
# usage: tab2html < inbut.txt > output.html
awk $* -- '
BEGIN {
FS=":" # field-separator: which character separats fields in a record (i.e. in a line)
print "<!DOCTYPE html>"
print "<html>"
print " <head>"
print " <style>"
print " table{border:1px solid black;border-collapse:collapse;}"
print " tr:nth-child(even){background-color: #f2f2f2;}"
print " td{border:1px solid black;padding:15px;}"
print " </style>"
print " <title>Tabular Data</title>"
print " </head>"
print " <body>"
print " <div style=\"overflow-x:auto;\">"
print " <table>"
}
{
print " <tr>"
for (i = 1; i <= NF; i++) { print " <td>"$i"</td>" }
print " </tr>"
}
END {
print " </table>"
print " </div>"
print " </body>"
print "</html>"
}
'

21
P01_Bash/tab2xml.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
# produces an XML file from a tabular file (given on stdin) with columns separated by ":"
# usage: tab2xml < inbut.txt > output.xml
awk $* -- '
BEGIN {
FS=":" # field-separator: which character separats fields in a record (i.e. in a line)
print "<?xml version=\"1.0\" standalone=\"yes\"?>"
print "<Table>"
}
{
print " <Row>"
for (i = 1; i <= NF; i++) { print " <Col>"$i"</Col>" }
print " </Row>"
}
END {
print "</Table>"
}
'