Colon separated list to regex or newline scripts

This commit is contained in:
inigoortega 2019-09-16 11:10:14 +02:00
parent b895021361
commit 0f43640f29
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,28 @@
#!/bin/sh
usage() {
echo "$0 [-r] <Colon separated list>" 1>&2
echo "[-r] Adds /.* at the end of each entry as if they were folders" 1>&2
exit 1
}
# To get options provided to the command
while getopts ":r" option; do
case "${option}" in
r)
recursive="1"
;;
* | h)
usage
;;
esac
done
shift $((OPTIND-1))
[ -z "$1" ] && exit 1
if [ "$recursive" = "1" ]; then
echo "$1/.*" | sed 's/:/\/.*\n/g'
else
echo "$1" | tr ':' '\n'
fi

View File

@ -0,0 +1,28 @@
#!/bin/sh
usage() {
echo "$0 [-r] <Colon separated list>" 1>&2
echo "[-r] Adds /.* at the end of each entry as if they were folders" 1>&2
exit 1
}
# To get options provided to the command
while getopts ":r" option; do
case "${option}" in
r)
recursive="1"
;;
* | h)
usage
;;
esac
done
shift $((OPTIND-1))
[ -z "$1" ] && exit 1
if [ "$recursive" = "1" ]; then
echo "\($1/.*\)" | sed 's/:/\/.*\\|/g'
else
echo "\($1\)" | sed 's/:/\\|/g'
fi