I need to transform xxx#yyy@zzz
to look like ZZZ xxx-yyy
using a script. I am already using a case statement in the script, so should I use an if statement before the case statement or should I continue with the case statement? here is my current script
function usage
{
echo "usage: $0 arguments ..."
if [ $# -eq 1 ]
then echo "ERROR: $1"
fi
}
# Script begins here
if [ $# -gt 0 ]
then
echo "Joe Fosteson"
date
echo
for arg
do
case $arg in
rootjobs)
echo "Root is running $(ps -U root -u root u | wc -l) processes on $(una
me)."
;;
student_accounts)
echo "There are $(ls -1 /home/student/ | wc -l) student accounts on $(ho
stname)."
;;
*)
usage "Do not know what to with $arg"
;;
esac
echo "*****"
done
else
usage
fi
Here is the sed commands i was using but it is not correct format........
if [ $# -eq 0 ]
then echo "Please enter a file name"
else echo
if test -f $1
then
#s1.sh
starting_data=$1
sed 's/ //' $starting_data > raw_dataz
sed "/^id/ d" raw_dataz > new
cut -f1 -d, new > id1
sed 's/ //' id1 > id2
cut -f2 -d, new > lastname1
sed 's/ //' lastname1 > lastname2
cut -f3 -d, new > firstname1
sed 's/ //' firstname1 > firstname2
awk '{print $0":"}' lastname2 > lastname3
sed -e 's/-//g' id2 > id3
paste -d\ firstname2 lastname3 id3 > final
cat final
else echo "$1 cannot be found"
fi
fi
To convert a string like xxx#yyy@zzz
to ZZZ xxx-yyy
in bash:
str='xxx#yyy@zzz'
if [[ "$str" =~ (.+)#(.+)@(.+) ]]; then
str2="${BASH_REMATCH[3]^^} ${BASH_REMATCH[1]}-${BASH_REMATCH[2]}"
echo "$str2"
else
echo "Bad string format"
fi
In sed
sed -r 's/(.+)#(.+)@(.+)/\U\3\E \1-\2' <<<"$str"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments