Write A Shell Program To Check The Given String: Is Palindrome or Not
Write A Shell Program To Check The Given String: Is Palindrome or Not
IS PALINDROME OR NOT.
l=0
Cnt=l
Tag=0
Read str
1= ‘echo $ str/wc-c
l= ‘expr $ ½’
while [ $ cnt- le $ lh ]
do
c2 = ‘echo $ str/cut-c $ 1’
if [ $ cl ! = $ c2]
then
cut = $lh
tag = l
fi
= ‘ expr $ 1-1”
Done
If [ $ tag - ego]
Then
Else
fi
OUTPUT:
WRITE A SHELL PROGRAM TO FIND FACTORIAL.
read num
fact=1
n=$num
do
let num--
done
OUTPUT:
WRITE A SHELL PROGRAM TO FIND BIGGEST AMONG
THREE NUMBERS.
Echo “Enter A value:”
Read a
Read b
Read c
Then
Then
Else
fi
OUTPUT:
IMPLEMENTATION OF LINK AND UNLINK IN C.
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
exit(0);
STUDY ABOUT THE GENERAL PURPOSE UTILITIES :-
(A) BANNER
(B) CAL
(C) DATE
(D) TTY
(E) BC
(F) SPELL AND FSPELL
(A) BANNER :-
The Unix banner program outputs a large ASCII art version of the text that is
supplied to it as its program arguments. One use of the command is to create
highly visible separator pages for print jobs.
Implementation
The way that the program is implemented internally is error-prone and antiquated.
The character fonts used are hardwired into the program code itself, as statically
initialized data structures. Two data structures are used. The first is a data table
comprising a sequence of printing instructions that encode the bitmap for each
character (in an encoding specific to the banner program). The second is an index
into that table that indicates, for each character code, where the printing
instructions for that character begin and end.
Operation
A related, and more flexible, program is figlet, which can display text in different
fonts and orientations.
SYNTAX:
$banner
(B) CAL :-
cal is a standard program on Unix and Unix-like operating systems that prints an
ASCII calendar of the given month or year. If the user does not specify any
command-line options, cal will print a calendar of the current month.
SYNTAX:
$cal
Examples
$ cal
April 2010
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
(C) DATE :-
Date" is utility to set the time and create a timestamp is user-defined format in
Unix, Linux or BSD system. It does not have the ability to convert one timestamp
representation into another but BSD variant has the ability to convert date
representation in seconds to any format you wish. there are also numerous "Unix
timestamp calculators" on the WEB. for example
It was first seen in Version 1 of AT&T Unix, circa 1969, and has both grown and
improved over the years to provide you with a wide variety of configurable options
for your system.
The most important for scripting functionality of date is the the ability to create
timestamp is wide variety of formats.
2010/01/04 06:28
If you are ok with two year year representation you can use %y instead of %Y.
There is also a macro %D that provides date in mm/dd/yy format, so we can
rewrite the previous example as
* %% a literal %
* %a locale's abbreviated weekday name (Sun..Sat)
* %D date (mm/dd/yy)
* %H hour (00..23)
* %m month (01..12)
* %M minute (00..59)
* %n a newline
* %p locale's AM or PM
* %S second (00..60)
* %t a horizontal tab
* %Y -- ccyy year
Date also can work not with the current time but with time of modification of the
referenced file
20060709
20060702
20060627
20060604
20050704
20060711
20060804
20070704
1240596879
Or:
Examples
date "+%-m/%-d/%y"
7/4/06
date "+%Y%m%d"
20060704
2010/03/13
echo $DATE
20060704
START=`date '+%r'`
echo $START
03:06:02 PM
sleep 5
echo $START
03:06:02 PM
echo $DATE
20060704
export TZ=$OLDTZ
20060709
20060702
20060627
20060604
20050704
20060804
20070704
(D) TTY :-
tty is a Unix command that prints to standard output the name of the file connected
to standard input. The name of the program comes from teletypewriter, abbreviated
"TTY".
SYNTAX:
$tty
$ tty
/dev/pts/4
The pts indicates that it is a pseudo terminal, with the number following it. If the
program was run on a true tty, it would output something like this:
$ tty
/dev/tty2
(E)BC :-
The operators:
^ ^=
... resemble the C bitwise exclusive-or operators, but are in fact the bc integer
exponentiation operators.
'Missing' operators relative to C
& | ^ && || ^^
<< >>
<<= >>=
?:
The sqrt() function for calculating square roots is POSIX bc's only built-in
mathematical function. Other functions are available in an external standard
library.
Standard library functions
bc's standard math library (defined with the -l option) contains functions for
calculating sine, cosine, arctangent, natural logarithm, the exponential function and
the two parameter Bessel function J. Most standard mathematical functions
(including the other inverse trigonometric functions) can be constructed using
these. See external links for implementations of many other functions.
Please, note that the scale changes with the -l option to 20 (source). So things such
as modulo may work unexpectedly. For example, write "bc -l" and then the
command "print 3%2" outputs 0, instead of 1. But if you do it like "bc -l",
"scale=0" and then the command "print 3%2" has 1 as output.
Plan 9 bc
GNU bc derives from the POSIX standard and includes many enhancements. It is
entirely separate from dc-based implementations of the POSIX standard and is
instead written in C. Nevertheless, it is fully backwards compatible as all POSIX
bc programs will run unmodified as GNU bc programs.
GNU bc variables, arrays and function names may contain more than one
character, some more operators have been included from C, and notably, an if
clause may be followed by an else.
Output is achieved either by deliberately not assigning a result of a calculation to a
variable (the POSIX way) or by using the added print statement.
The value of the last calculation is always stored within the additional built-in last
variable.
Extra operators
&& || !
... and are available for use in conditional statements (such as within an if
statement). Note, however, that there are still no equivalent bitwise or assignment
operations.
Functions
All functions available in GNU bc are inherited from POSIX. No further functions
are provided as standard with the GNU distribution.
One of the simplest, and sometimes most convenient, of these spelling checkers is
the spell command. Despite its lack of sophisticated features, it is still worth being
aware of spell for several reasons, including (1) it is very easy to use, (2) it can be
found on many Unix-like systems and (3) it is well suited for use with other
commands linked by pipes (which are used to combine commands).
spell compares words typed in at the keyboard or the contents of a text file to those
in a built-in dictionary file and then writes all of the words not in the dictionary
(and, therefore, presumably misspelled) to standard output (which is the display
screen by default).
On some systems spell is a stand-alone program, either the original version or the
GNU clone. On others, such as Red Hat Linux 9, it is a shell script (i.e., a simple
program) that launches a simplified version of another spelling checking program,
aspell, which emulates the core function of spell.
spell displays each presumably misspelled word on a new line. In the case of the
Red Hat version, the words are displayed in alphabetic order and each erroneous
spelling is displayed only once, regardless of the number of times that it appears in
the text. If multiple files are specified for checking, a single, alphabetized list of
words is still generated.
spell's syntax is
For example, it can easily be determined whether the word desireable is spelled
correctly by first entering at the command line the spell command, pressing the
RETURN key, typing the word desireable, pressing RETURN again and then
simultaneously press the CONTROL key and the d key. The output will look like
the following:
$ spell
desireable
desireable
$
The word desireable is echoed (i.e., repeated by the system) because it is not in the
system dictionary and is thus quite likely a spelling error. If the same procedure is
repeated using desirable (i.e., omitting the second e), then it is not echoed, because
it is in the system dictionary and is therefore the correct spelling. Thus, the screen
would look like:
$ spell
desirable
$
spell can also be used with lists of words and sentences. For example, typing spell,
pressing the RETURN key, typing the sentence This is the storry abuot an
operating system that went from baad to wurse, pressing RETURN again, and
finally simultaneously pressing the CONTROL key and the d key would produce
the following output:
$ spell
This is the storry abuot an operating system that went from baad to wurse
abuot
baad
storry
wurse
$
To find any spelling errors in a file, all that is necessary to supply the name of the
file as an argument after the command and any options. For example, the following
will search for errors in a file named file1:
spell file1
spell can be used to check any number of files simultaneously by listing them all as
arguments, for example:
It is then a simple matter to correct the misspellings using a text editor (e.g., vi or
gedit).
As is the case with other filters, the output of spell can be redirected from standard
output using the standard output redirection operator, which is designated by a
rightward facing angular bracket. For example, the following tells spell to check
the spelling of all words in the first three files and write its output to file4 instead
of to the display screen:
The output of spell can also be further processed by using pipes to send it to other
filters. For example, in the following example the output of spell is piped to grep
(which is used to search for files and the contents of files) in order to display only
those misspelled words in file5 that contain the sequence of letters com
The output could likewise be redirected to a file instead of to the display screen,
such as to a new or existing file named file6:
spell file5 | grep com > file6
Although spell is very useful for checking text against the several tens of thousands
of commonly used words in the English language that are included in the
dictionary file, it does not do a good job of checking technical terminology, proper
nouns (e.g., names of people, places and products) and slang.
Also, spell is not interactive. That is, it does not highlight misspelled words in a
file and assist the user in correcting them one by one in the context of the text.
However, this can be an advantage in some cases, particularly if the user merely
wants to see a list of the potentially misspelled words in a file without having to go
through and attempt to correct all of them.
Moreover, some of the useful features that come with the original version of spell
are not found on the aspell emulation version. For example, the original Unix
version has several options, including -b, which accepts UK spellings (e.g. labour,
colour, centre), and -x, which displays every possible stem for each word. The
original version also allows users to create their own supplementary dictionary
files, which can be very useful for adding technical terms and proper nouns.
When more features are desired for a command line spelling checker than are
available on the the aspell emulation version, the user should consider installing
the original version of spell or its GNU clone or using a more sophisticated
program such as aspell or ispell, both of which are interactive and allow the use of
user-created dictionaries. aspell is better at making suggestions when a word is
seriously misspelled, whereas ispell has the advantage that it can be used with
numerous foreign languages.
This article was written using the gedit text editor on a Red Hat 9 Linux machine.
spell was used to check the spelling after the final proofreading by the author, and
it found several errors. Interestingly, the only word that was misspelled multiple
times was the word misspell itself, which was spelled mispell.
IMPLEMENTATION OF GREP COMMAND IN C.
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
/* calculate filesize */
int calc_bufsize(char *filename)
{
struct stat st;
stat(filename, &st);
return ((int)st.st_size);
}
FILE *fp;
char *filename;
int x = 2;
IMPLEMENTATION OF WE COMMAND IN C.
void main()
/* Prompt user for file and count number of characters
and lines in it*/
{
FILE *fopen(), *fp;
int c , nc, nlines;
char filename[40] ;
nlines = 0 ;
nc = 0;
if ( fp == NULL )
{
printf("Cannot open %s for reading \n", filename );
exit(1); /* terminate program */
}
c = getc( fp ) ;
while ( c != EOF )
{
if ( c == '\n' )
nlines++ ;
nc++ ;
c = getc ( fp );
}
fclose( fp );
if ( nc != 0 )
{
printf("There are %d characters in %s \n", nc, filename );
printf("There are %d lines \n", nlines );
}
else
printf("File: %s is empty \n", filename );
}
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
FILE *fopen(),*fp;
int c,count=1,count2=1;
char file_name[50];
printf("Enter The file name :");
gets(file_name);
fp=fopen(file_name,"r");
if ( fp == NULL )
{
printf("Cannot open %s for reading \n", file_name );
exit(1); /* terminate program */
}
c=getc(fp);
while(c!=EOF)
{
if(c=='\n')
count++;
c=getc(fp);
}
fclose(fp);
fp=fopen(file_name,"r");
c=getc(fp);
while(c!=EOF)
{
if(c=='\n')
count2++;
if(count2%49==0)
{
per=(count2/count)*100;
printf("--MORE--%d%",per);
}
c=getc(fp);
}
fclose(fp);
}
IMPLEMENTATION OF LS COMMAND IN C.
#include<iostream.h>
#include<sys/types.h>
#include<direct.h>
#include<stdlib.h>
if (argc==2)
{
dp = opendir(argv[1]);
while ((dirp = readdir(dp)) != NULL)
printf("%s\n", dirp->d-name);
}
else
{
if (argc == 1)
{
dp = opendir(".");
while ( (dirp = readdir(dp)) != NULL)
printf("%s\n", dirp->d-name);
}
else
{
printf("ls - Error - too many parameters\n");
exit(0);
}
};
closedir(dp);
return 0;
}
Output
INDEX
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
/* calculate filesize */
int calc_bufsize(char *filename)
{
struct stat st;
stat(filename, &st);
return ((int)st.st_size);
}
FILE *fp;
char *filename;
int x = 2;
fclose(fp);
}
return 0;
}