Skip to content

Instantly share code, notes, and snippets.

@SKocur
Created May 13, 2019 11:58
Show Gist options
  • Save SKocur/d4ca70ecda8a268db53e281533a65a8d to your computer and use it in GitHub Desktop.
Save SKocur/d4ca70ecda8a268db53e281533a65a8d to your computer and use it in GitHub Desktop.
Bash exercises
#!/bin/bash
for INPUT in $(cat $1) ; do
if [ $(echo $INPUT | egrep -c "^[0-9]$") -eq 1 ] ; then
echo $INPUT >> $2
else
echo $INPUT >> $3
fi
done
#!/bin/bash
QN=0 #quantity of numbers
QW=0 #quantity of words
for L in $(cat $1) ; do
let RES=L%2
if [ $(echo $L | egrep -c "[0-9]+") -ne 0 ] ; then
let QN+=1
if [ $RES -eq 0 ] ; then
echo $L >> $2
else
echo $L >> $3
fi
else
let QW+=1
fi
done
echo "Quantity of numbers: "$QN
echo "Not numbers: "$QW
#!/bin/bash
C=0
for ARG in $@ ; do
if [ $C -gt 0 ] ; then
if [ -f $ARG ] && [ -w $ARG ] ; then
if [ $(cat $ARG 2> /dev/null | wc -l) -eq 0 ] ; then
echo $ARG >> $1
fi
fi
if [ $(ls $ARG 2> /dev/null | wc -l) -eq 0 ] ; then
echo $ARG >> $1
fi
fi
let C+=1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment