![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using sed to print a ruler | doubleminus | UNIX for Dummies Questions & Answers | 5 | 05-04-2008 01:15 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
||||
|
||||
|
ruler
Hi,
I remembered that I used the ruler command at the unix prompt. But I tried to use it again and it says that command not found. I don't know what had happened. It's in the command not in VI, right? Thanks! |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
I use my own ruler script....
Code:
# ./ruler.sh 50
5 10 15 20 25 30 35 40 45 50
....|....|....|....|....|....|....|....|....|....|
Code:
#! /bin/ksh
if [ "$#" -ne "1" ]; then
echo "usage: `basename $0` width"
exit 1
fi
if [ "$1" -lt "1" -o "$1" -gt "100" ]; then
echo "ruler: invalid width entered"
echo "please enter width between 1 and 100"
exit 1
fi
# First step
# ==========
# Print char numbers
#
size=$1
i=0
count_cntl=0
while [ "$i" -le "$size" ]
do
let "count_cntl = $count_cntl + 1"
if [ "$count_cntl" -eq 5 ]; then
count_cntl=1
fi
if [ "$i" -eq "0" ]; then
let "i = $i + 1"
continue
fi
mod=$(( $i % 5 ))
if [ "$mod" -eq "0" ]; then
echo "${i}\c"
else
if [ "$i" -lt "10" ]; then
echo " \c"
else
if [ "$count_cntl" -eq 3 ]; then
let "count_cntl = $count_cntl + 1"
else
echo " \c"
fi
fi
fi
let "i = $i + 1"
done
echo ""
# Second step
# ===========
# Print ruler itself
size=$1
i=0
while [ "$i" -le "$size" ]
do
if [ "$i" -eq "0" ]; then
let "i = $i + 1"
continue
fi
mod=$(( $i % 5 ))
if [ "$mod" -eq "0" ]; then
echo "|\c"
else
echo ".\c"
fi
let "i = $i + 1"
done
echo "\n"
exit 0
ZB |
||||
| Google The UNIX and Linux Forums |