Wednesday, August 13, 2014

Highlight wrongly spelt words in unix text file

#usage : scriptname file-name
#this is just the logic, basic validation is only done here
#it can be improved in a better manner.

#Some UNIX flavors have utilities which check the spellings.

while read v_line
do
IFS=" "
 for v_eachword in $v_line
  do
   grep -i `echo $v_eachword | tr -d '[[:punct:]]'` /usr/dict/words >/dev/null
   v_status=$?
   if [ $v_status -eq 0 ]
   then
    echo "$v_eachword \c"
   else
    echo "\033[32m" "$v_eachword \c"
   fi
  echo "\033[0m\c"
  done
echo

done < $1


DEMO:
phani >more spell_correct
This file is creatd to check whether the spellings are correct or wrongg in this file.
It jus checks the spellings not the grammer.
phani >check_spell spell_correct
This file is creatd to check whether the spellings are correct or wrongg in this file.
It jus checks the spellings not the grammer.

phani >

COLORS to your Shell

## Colors to your shell is nothing but colors to the ANSI console. As both are same...

## You tell the console with the codes which mention the #colors..

## I hope below simple commands are self explaining. use #the comment box if you have any doubts..


fg_black="\033[30m"
fg_red="\033[31m"
fg_green="\033[32m"
fg_yellow="\033[33m"
fg_blue="\033[34m"
fg_purple="\033[35m"
fg_cyan="\033[36m"
fg_white="\033[37m"

bg_black="\033[40m"
bg_red="\033[41m"
bg_green="\033[42m"
bg_yellow="\033[43m"
bg_blue="\033[44m"
bg_purple="\033[45m"
bg_cyan="\033[46m"
white="\033[47m"

on_bold="\033[1m"
off_bold="\033[22m"
on_italic="\033[3m"
off_italic="\033[23m"
on_uline="\033[4m"
off_uline="\033[24m"
on_inv="\033[7m"
off_inv="\033[27m"

off_all="\033[0m"


echo "$fg_yellow" "$bg_red" "Danger !! Danger !!"
echo "$off_all"

Friday, August 8, 2014

Move text round and round on same line in UNIX

## Move Text ROUND and ROUND on same line in UNIX
## Script is self explaining. Use the comment box for any doubts


move_text()
{
#USAGE: move_text "TEXT TO ROTATE" "NUMBER_OF_TIMES"
 typeset -i i k m count;
 m=0;
 count=${2:-2}
 while [ "$m" -lt $count ]
 do
  i=0;
  k=1;
  while [ "$i" -lt 10 ]
  do
   j=0;
   while [ "$j" -lt "$k" ]
   do
     echo "\t\c"
     j=$((j+1))
   done
   echo "$1\c"
   sleep 1
   tput cub 100
   i=$((i+1));
   k=$((k+1))
  done

  m=$((m+1))
  tput el1
  tput el
 done
echo
}

move_text "...I can move 5 times...." 5

move_text "...I can move 2 times...."    #default parameter will be taken as 2