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

Thursday, May 29, 2014

Bully your colleague in UNIX shell

Hi Folks,

Most of the Production Support Engineers will be having their Databases on Unix server.

In those cases most of the time you folks will be using Unix Shells. Then here is a small Unix command to make fun of the colleague who is logged in the same Unix Shell.

write is the unix command which helps to write messages to other person terminal.

syntax:

write username [ttyname]

Examples:

Simple:

banner  server crashed | write joel pts/4

More realistic:

(
 echo "\n\n ------------------------SERVER REBOOT INITIATED-----------------------"
 echo " completed   8% .."
 sleep 2
 echo " completed  24% .."
 sleep 3
 echo " completed  32% .."
 sleep 4
 echo " completed  90% .."
 sleep 2
 echo " completed 100% .."
 echo "\n\n ------------------------SERVER REBOOT COMPLETED-------------------------"
 echo "\nPlease press enter to Exit session..."
 ) | write agtmgt pts/13

Note: Make fun when your colleague is deeply investigation. Yeah, thats real fun folks..

Thursday, March 20, 2014

C Program to Remove Comments from the C File

C Program to Remove Comments from the File

Description: This program removes comments starting with '//' i.e., single line comments..
You can edit it to remove '--' comments in SQL by just editing the condition..

#include<stdio.h>
#include<ctype.h>
#include<string.h>
 
#define MAXSIZE 1000
 
main()
{
 
 char c, line[MAXSIZE], oline[MAXSIZE];
 int  i=0, linesize=0, doubleq=0;
 
 FILE *ip ,*op;
 
 clrscr();
 
 
 ip = fopen( "input_ph.txt","r");
 op = fopen( "out_ph.txt","w+");
 
 
  while ( (fgets(line,1000,ip)) != NULL )
   {
    linesize = strlen(line);
 
    for(i=0;i<linesize;i++)
    {
     if ( line[i] == '"' )
     doubleq++;            //for validation of '//' in double quotes
 
     if ( !((line[i] == '/') && (line[i+1] == '/')) || (doubleq%2 == 1) )
     oline[i] = line[i];        //copy char by char to OLINE array
 
     else
     {
     oline[i]='\n';
     oline[i+1]='\0';
 
     doubleq = 0;
     break;     //break out from reading char by char once you find comment i.e., '//'
     }
    }
 
    fputs(oline,op);   //put the line truncated from comments to the output file.
    for(i=0;i<linesize;i++)   //null the arrays
    {
     oline[i]=NULL;
     line[i]=NULL;
    }
    i=0;
  }
 
  fclose(ip);
  fclose(op);
 
 getch();
 return 0;
}

Wednesday, February 26, 2014

Replacing text in all files in unix

##########################################################

for f_name in `ls file*`
do

 more $f_name | sed "s/$1/$2/g" > f_name_temp
 mv f_name_temp $f_name

done

##########################################################

Experiment:

IOB_ksh >more file1 file2 file3
::::::::::::::
file1
::::::::::::::
this is file1
::::::::::::::
file2
::::::::::::::
this is file2
::::::::::::::
file3
::::::::::::::
this is file3

IOB_ksh >changeallfiles.sh this Dis

IOB_ksh >more file1 file2 file3
::::::::::::::
file1
::::::::::::::
Dis is file1
::::::::::::::
file2
::::::::::::::
Dis is file2
::::::::::::::
file3
::::::::::::::
Dis is file3

Comments:
The for loop condition should be changed accordingly. This works only in current directory files.



Monday, December 31, 2012

Last post of the year 2012

Hi to all the blog viewer's.

There were few posts this year, I am not sure weather they are interesting or not but I hope u like them...:)
Posts this year were not that frequent, I can promise this 2013 will have more frequent posts with interactive and interesting stuff.....;)

2012 posts were mostly TECHNICAL, which is not good right! ;) So this year will be a pack of music, treck's, sharing and then at last technical...

So goodbye to 2012..I here by welcome 2013 ...hiphip hurray
:)

Wednesday, June 6, 2012

Simplest logic for Time Display on LCD using 8051

/* here time starts from 0 seconds, you can add logic to set the time

not clear den try to make it clear or comment here */


#include reg51.h #include "lcd_display4bit.h" //for header check this void printTime(); long timerCount=; short int count=0; sbit getTime=P1^2; void CountSeconds() interrupt 1 {

Thursday, May 31, 2012

String Sorting Program in C (uses array of pointers to store strings)

/* string sorting program the logic may be simple but I have used array of pointers here to store the strings
crucial here is u should you malloc and calloc to get 
correct output(because array of pointers are used)*/ #include stdio.h #include string.h #define MAX 50 void main() { char *names[MAX],*dummy; int i=0,j=0,n=0; clrscr(); puts("enter no. of strings you want to enter"); scanf("%d",&n); printf("please enter %d strings\n\n",n);

Sunday, May 27, 2012

Scramble word finder- C program

/* C program for SCRAMBLE word finding
Download a wordlist.txt file on internet which consists of
all possible english words and save it in your program folder
before running the program. */


#include stdio.h #include string.h void main() { FILE *fp; char scramble[12],word[18],dummy[18],c; int i=0,j=0,wordLen,wordLenS,count=0; clrscr(); fp=fopen("wordlist.txt","r"); printf("enter scrambled word--"); scanf("%s",scramble); wordLenS=strlen(scramble);

Wednesday, May 16, 2012

Pattern Finder in all DIRECTIONS in a GRID of numbers -C program

/* Pattern Finder in all DIRECTIONS in a GRID of numbers -C program
you are allowed to enter a pattern of any length then the ROW and
COL of the pattern occurence is shown in the output.
pattern is searched in ALL THE EIGHT DIRECTIONS */


#include stdio.h #include string.h short int checkPattern(int,int,int); short cp[8][8]={5,4,1,2,3,4,5,6, 6,3,1,2,3,4,5,5, 5,7,5,3,5,1,3,1, 4,1,7,4,3,4,5,1, 3,2,3,4,5,1,5,2, 2,2,5,2,1,4,1,3, 1,4,7,8,6,5,4,4, 6,5,3,2,6,7,8,5}; char p[5]; void main() { int i,j,k;

Friday, May 11, 2012

Password STRENGTH and VALIDITY checking C program

/* password Strength and Validity checking C program-

This program takes your password and checks weather its valid
are not.
If valid then its checks the password strength and gives
one of the following result : LOW, MEDIUM, HIGH, VERY HIGH.


note-this is my algorithm(most followed), you can change as you need.
*/


#include stdio.h #include conio.h #include string.h #define SIZE 32 short int checkValid(char*); void checkStrength(char*); short int alphabetCount=0, digitCount=0; short int length=0; short int symbolCount=0; //to count symbols like ;'./ etc void main() { char pw[SIZE],c; short int count,error,i=0; clrscr();