Showing posts with label Unix&ShellProgramming. Show all posts
Showing posts with label Unix&ShellProgramming. Show all posts

Monday, January 20, 2014

Unix and Shell Programming - Background Process Manipulation

with 0 Comment
while true
do
echo "Background Process Manipulation"
echo "----------------------------------"
echo "Menu"
echo "------"
echo "1.Create a Background Process"
echo "2.List the Background Process"
echo "3.Kil a Process"
echo "4.Exit"
echo "Enter your choice"
read ch
case $ch in

1)
echo "Create a Background Process"
echo "------------------------------"
echo "Enter the Command to be Execute as Background"
read cmd
$cmd &
echo "$cmd Is Executed as a Background Process"
echo ""
;;

2)
echo "List the Current Process"
echo "-------------------------"
echo
ps
;;

3)
echo "Kill the Process"
echo "----------------"
echo
echo "Enter the Process id:"
read id
kill $id
echo $id "is Terminated"

4)
Exit
;;
esac
done

-----------
OUTPUT:
-----------
Background Process Manipulation
-----------------------------------
Menu
------
1.Create a Background Process
2.List the Background Process
3.Kil a Process
4.Exit

Enter your choice
1

Create a Background Process
-------------------------------
Enter the command to be Executed as Background
sleep300

sleep300 Is Executed as a Background Process

Enter your choice
2

List the Current Process
-------------------------
PID         TTY           TIME        CMD
4688   pts/15           00:00:00       bash
19739 pts/15           00:00:00        sh
19778 pts/15          00:00:00       sleep
19779 pts/15          00:00:00         ps

Enter your choice
3

Kill the Process
----------------
Ener the Process id:
19739

Terminated

Unix and Shell Programming - Sorting a Database

with 0 Comment
clear
ch==1
echo "Sorting a Database"
echo "-------------------"
echo "Enter the Databse Name"
read fn
echo "Content of the File"
cat $fn
echo "Before Sorting"
echo "---------------"
echo ""
echo "USN Name    SEM/BRANCH     SEX    DOB"
echo "----    -----         -------------       ----      ----"
cat $fn
echo ""
echo "After Sorting"
echo "-------------"
echo ""
echo "USN    NAME   SEM/BRANCH    SEX   DOB"
echo "----        -----         -------------       ----     ---"
sort -t\| +1 -2 $fn
echo ""


-----------
OUTPUT:
-----------
Sorting a Database
-------------------
Enter the Database Name
stud

Content of the file
------------------
ISO23    |rashmi bangera      |V       ISE      |F   |03/09/85
ISO38    |b h yatheesh         |V       ISE      |M   |03/02/85
CSO18    |karthik iyer          |V       CSE     |M   |02/05/84
CSO24    |Sourab guptha      |V       CSE      |M   |01/06/84
ISO06    |ashish rastagi       |V       ISE      |M   |03/07/84
CSO55    |vaishnavi sargod  |V       CSE     |F   |02/11/85
ISO17     |Poorvi prasad      |V       ISE      |F   |11/01/84

Before Sorting
---------------

USN         NAME      SEM/BRANCH     SEX         BOB
----         ------     -------------     ----         ----
ISO23    |rashmi bangera      |V       ISE      |F   |03/09/85
ISO38    |b h yatheesh         |V       ISE      |M   |03/02/85
CSO18    |karthik iyer          |V       CSE     |M   |02/05/84
CSO24    |Sourab guptha      |V       CSE      |M   |01/06/84
ISO06    |ashish rastagi       |V       ISE      |M   |03/07/84
CSO55    |vaishnavi sargod  |V       CSE     |F   |02/11/85
ISO17     |Poorvi prasad      |V       ISE      |F   |11/01/84

After Sorting
-------------
USN         NAME      SEM/BRANCH     SEX         BOB
----         ------     -------------     ----         ----
ISO06    |ashish rastagi       |V       ISE      |M   |03/07/84
ISO38    |b h yatheesh         |V       ISE      |M   |03/02/85
CSO18    |karthik iyer          |V       CSE     |M   |02/05/84
ISO17     |Poorvi prasad      |V       ISE      |F   |11/01/84
ISO23    |rashmi bangera      |V       ISE      |F   |03/09/85
CSO24    |Sourab guptha      |V       CSE      |M   |01/06/84
CSO55    |vaishnavi sargod  |V       CSE     |F   |02/11/85

Unix and Shell Programming - List and Delete Zero Bytes File

with 0 Comment
while true
do
echo "Menu"
echo "------"
echo "1.List the zero byte files"
echo
echo "2.Delete the zero byte files"
echo
echo "3.Exit"
echo
echo "Enter your choice"
read ch
case $ch in

1)
echo "List of Zero byte files"
echo "---------------------"
echo
flag=0
for i in*
do
if[-f $i -a ! -s $i]
then
ls -l $i
flag=1
fi
done
if[$flag=0]
then
echo "No Zero bytes files"
echo
fi
;;

2)
echo "Delete the zero bytes files"
echo "--------------------------"
echo
flag=0
for i in*
do
if[-f $i -a ! -s $i]
then
rm -i $i
flag=1
fi
done
if[$flag=0]
then
echo "No Zero bytes for Information"
echo
fi
;;

3)
echo "Exit"
exit
;;
esac
done

-----------
OUTPUT:
-----------
Menu
------
1.List the zero byte files
2.Delete the zero byte files
3.Exit

Enter your choice
1

List of zero byte choice
------------------------
-rw-rw-r--  1  smca13   smca13    0 Sep 26  15:17  count1
-rw-rw-r--   1 smca13   smca13    0 Oct 11  16:43  qyes
-rwxrwxrwx    1 smca13  smca13    0 Jan 30   2010  rithika
---x--x--x    1  smca13   smca13  0 Jan 30   2010  viji

Enter your choice
2

Delete the Zero bytes files
---------------------------
rm:remove regular empty file 'count1'?n
rm:remove regular empty file 'qyes'? y
rm:remove regular empty file 'rithika'?n
rm:remove write-protected regular empty file 'viji'?n

Enter your choice
1

List of Zero byte files
----------------------
-rw-rw-r--    1   smca13   smca13    0 Sep 26 15:17  count1
-rwxrwxrwx   1  smca13     smca13    0 Jan 30   2010  rithika
--x--x--x      1 smca13    msca13    0 Jan 30    2010 viji

Enter your choice
3
Exit

Unix and Shell Programming - Getting Input Alternate from Keyboard & File

with 0 Comment
clear
echo "Getting Inputs Alternate from the keyboard"
echo "-------------------------------------------"
echo
dv='tty'
echo -e "\nEnter the file name:\c"
read file
echo
echo "Contents of the file"
echo "-------------------"
echo
cat $file
echo "OUTPUT"
echo "----------"
echo
echo ""
if[-f $file]
then
exec<$file
while read line
do
echo $line
echo -e "\nEnter your the Answer:\c"
read ans<$dv
while[-z $ans]
do
echo -e "\nEnter your the Answer:\c"
read ans<$dv
done
echo "Answer:"$ans
echo
done
else
echo "File does not exists"
fi


-----------
OUTPUT:
-----------
Getting Inputs Alternate from the Keyboard
--------------------------------------------
Enter the file name:ques

Contents of the file
-------------------
1.What is your name?
2.What is your friend name?
3.What you finished your programs?

OUTPUT
----------
1.What is your name?
Enter your the Answer: Ashok
Answer:Ashok

2.What is your friend name?
Enter your the Answer:Raji
Answer:Raji

3.When you finshed your programs?
Enter your the Answer:yes
Answer:yes

Unix and Shell Programming - Copying a File Using Command Line Arguments in C

with 0 Comment
#include<stdio.h>
main(int argc,char *argv[])
{
FILE *f1,*f2;
char c[50];
int i;
f1=fopen(argv[1],"w");
for(i=2;i<argc;i++)
{
fprintf(f1,"%s\n",argv[i]);
}
fclose(f1);
f1=fopen(argv[1],"r");
f2=fopen("copy.txt","w");
for(i=2;i<argc;i++)
{
fscanf(f1,"%s\n",c);
fprintf(f2,"%s\n",c);
}
fclose(f2);
fclose(f1);
return(0);
}


-----------
OUTPUT:
-----------
[smca13@SRNM smca13]$ cc cmdline1.c
[smca13@SRNM smca13]$ ./a.out cmdline1.c cmp ga vb mn kj
[smca13@SRNM smca13]$ cat copy .txt
cmp
ga
vb
mn
kj
[smca13@SRNM smca13]$ cat cmp
madurai
thrichy
chennai
delhi
banglore

Unix and Shell Programming - Sorting in C

with 0 Comment
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,i,j,t;
printf("Sorting\n");
printf("------\n");
printf("Enter the limit of number\n");
scanf("%d",&n);
printf("Enter the elements one by one\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Before Sorting\n");
printf("------------\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("After Sorting\n");
printf("-----------\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
}

-----------
OUTPUT:
-----------
[smca13@SRNM smca13]$ cc sortdbase.c
[smca13@SRNM smca13]$ ./a.out sortdbase.c

Sorting
-------
Enter the limit of number
5

Enter the elements one by one
20
53
12
86
48

Before Sorting
---------------
20
53
12
86
48

After Sorting
-------------
12
20
48
53
86

Unix and Shell Programming - Palindrome Number Checking

with 0 Comment
clear
echo "Palindrome Number Checking"
echo "------------------------------"
echo
echo "Enter the Number"
read n
s=0
n1=$n
while[$n -gt 0]
do
r='expr $n%10'
s='expr $s \* 10 + $r'
n='expr $n/10'
done
echo
echo "The Reverse Number is:"$s
if[$s -eq $n1]
then
echo
echo "The Given Number is Palindrome"
else
echo
echo "The Given Number is not Palindrome"
fi

-----------
OUTPUT:
-----------
Palindrome Number Checking
-------------------------------
Enter the Number
121

The Reverse Number is:121

The Given number is palindrome

Palindrome Number Checking
------------------------------
Enter the Number
122

The Reverse Number is:221

The Given Number is not palindrome

Unix and Shell Programming - Grep Command

with 0 Comment
clear
echo "Enter the file name"
read f
echo
cat $f
while true
do
echo "Grep Command"
echo "----------------"
echo
echo "Menu"
echo "-----"
echo
echo "1.Inverse"
echo
echo "2.Ignore"
echo
echo "3.File Name"
echo
echo "4.Line Number"
echo
echo "5.Count"
echo
echo "6.Multiple Search Options"
echo
echo "7.Exit"
echo
echo "Enter the choice"
read ch
case $ch in

1)
echo "Inverse"
echo "-------"
echo
echo "Contents of the file"
cat $f
echo "Enter the Search pattern"
read p
echo
grep -v $p $f
;;

2)
echo "Ignore"
echo "------"
echo
echo "Contents of the file"
cat $f
echo "Enter the Search pattern"
read p
echo
grep -i $p $f
;;

3)
echo "File Name"
echo "-----------"
echo
echo "Contents of the file"
cat $f
echo "Enter the Search pattern"
read p
echo
grep -l $p $f
;;

4)
echo "Line Number"
echo "--------------"
echo
echo "Contents of the file"
cat $f
echo "Enter the Search pattern"
read p
echo
grep -n $p $f
;;

5)
echo "Count Option"
echo "--------------"
echo
echo "Contents of the file"
cat $f
echo "Enter the Search pattern"
read p
echo
grep -c $p $f
;;

6)
echo "Multiple Search Options"
echo "-------------------------"
echo
echo "Contents of the file"
cat $f
echo "Enter the Search pattern1"
read p1
echo "Enter the Search pattern2"
read p2
echo
grep -e $p1 -e $p2 $f
;;

7)
echo "Exit"
echo "----"
exit
;;
esac
done


----------
OUTPUT:
----------
Enter the file name
cmp

Content of the file
------------------
madurai
thrichy
chennai
delhi
banglore

grep command
---------------
Menu
------
1.Inverse
2.Ignore
3.File Name
4.Line Number
5.Count
6.Multiple Search Options
7.Exit

Enter the Choice
1
Inverse
-------
Contents of the file
-------------------
madurai
thrichy
chennai
delhi
banglore

Enter the Search pattern
delhi

Content of the file
------------------
madurai
thrichy
chennai
banglore

Enter the choice
2

Ignore
-------
Contents of the file
-------------------
madurai
thrichy
chennai
delhi
banglore

Enter the seach pattern
CHENNAI

chennai

Enter the choice
3

File Name
-----------
Contents of the file
-------------------
madurai
thrichy
chennai
delhi
banglore

Enter the search pattern
thrichy

cmp

Enter the Choice
4

Line Number
--------------
Contents of the File
--------------------
madurai
thrichy
chennai
delhi
banglore

Enter the seach pattern
chennai

3:chennai

Enter the choice
5

Count Option
--------------
Contents of the file
-------------------
madurai
thrichy
chennai
delhi
banglore

Enter the search pattern
banglore

1
Enter the choice
6

Multiple Search Options
-------------------------
Contents of the file
-------------------
madurai
thrichy
chennai
delhi
banglore

Enter the search pattern1
thrichy
Enter the search pattern2
delhi

thrichy
delhi

Enter the choice
7
Exit

Unix and Shell Programming - Greet the User Based On System Time and User Time

with 0 Comment
clear
while true
do
echo "Greeting Command"
echo "------------------------"
echo
echo "Menu"
echo "-------"
echo "1.System Time"
echo "2.User Time"
echo "3.Exit"
echo "Enter your choice"
read ch
case $ch in

1)
echo "System Time"
echo "----------------"
hournow='date|cut -c 12-13'
echo "current date is:"
echo
date
echo
hr='date|cut -c 12-19'
echo
echo "Current Time is:"$hr
echo
user1='echo $HOME|cut -d"/" -f  3'
echo
case $hournow in
[0-1][0-1]|0[2-9])echo "Good Morning Mr/Ms:$user1";;
1[2-5])echo "Good afternoon Mr/Ms:$user1";;
1[6-9])echo "Good Evening Mr/Ms:$user1";;
*)echo "Good Night Mr/Ms:$user1";;
esac
;;

2)
echo "User Time"
echo "------------"
echo "Enter the time[hh:mm:ss]:"
read time1
echo
hr='echo $time|cut -c 1-2'
echo "The time is:"$time1
user='echo $HOME|cut -d "/" -f 3'
case $hr in
[0-1][0-1]|0[2-9])echo "Good Morning Mr/Mrs:$user1";;
1[2-5])echo "Good Afternoon Mr/Mrs:$user1";;
1[6-9])echo "Good Evening Mr/Mrs:$user1";;
*)echo "Good Night Mr/Mrs:$user1";;
esac
;;

3)
echo "Exit"
echo "---"
exit
;;
esac
done

------------
OUTPUT:
------------
Greeting Command
------------------------
Menu
-------
1.System Time
2.User Time
3.Exit
Enter your choice
1
System Time
----------------
Current date is:

Thu Oct 11 17:03:29  IST 2012
Current Time is : 17:03:29

Good Evening Mr/Ms:smca13

Enter your choice
2

User Time
-------------
Enter the time[hh:mm:ss]:
04:30:35

The time is:04:30:35
Good Night Mr/Mrs:smca13

Enter your chocie
3
Exit

Unix and Shell Programming - tr Command

with 0 Comment
clear
echo "Tr Commands"
echo "-----------------"
echo
echo "Enter the file name"
echo
read f
if[-f $f]
then
while true
do
echo
echo "Menu"
echo "-------"
echo
echo "1.Delete"
echo
echo "2.Squeeze"
echo
echo "3.Complement"
echo
echo "4.Exit"
echo
echo "Enter your choice"
echo
read n
case $n in
1)
echo "Delete"
echo "-------"
echo
echo "Content of the file"
echo "----------------------"
cat $f
echo "Enter the Character to be deleted"
read d
echo "After Deletion"
echo "------------------"
tr -d $d<$f
;;

2)
echo "Squeeze"
echo "----------"
echo
echo "Content of the file"
echo "----------------------"
cat $f
echo "Enter the Character to be changed"
read old
echo "After Squeeze"
echo "-----------------"
tr -s $old <$f
;;

3)
echo "Complement"
echo "----------------"
echo "Content of the file"
echo "----------------------"
cat $f
echo "Enter the Character not be changed"
read com
echo "Enter the replacing character"
read rep
echo "After Complement"
echo "-----------------------"
tr -c $com $rep<$f
;;

4)
echo "No Choice"
echo
exit
;;
esac
done
else
echo "File does not exit"
fi

-------------
OUTPUT:
-------------
Tr Commands
-----------------
Enter the file name
tr

Menu
-------
1.Delete
2.Squeeze
3.Complement
4.Exit

Enter your choice
1

Delete
--------
Content of the file
----------------------
A Friend is need the friend indeed

Enter the character to be deleted
e

After Deletion
------------------
A friend is nd th friend indd

Enter your choice
2

Squeeze
----------
Content of the file
----------------------
A friend is need the friend indeed

Enter the character to be changed
ee

After Squeeze
-----------------
A friend is ned the friend inded

Enter your choice
3

Complement
----------------
Content of the file
----------------------
A friend is need the friend indeed.

Enter the character not be changed
i

Enter the replacing character
-
After Complement
----------------------
---i---i--------------i---i------

Enter your choice
4
No Choice

Unix and Shell Programming - Count and Replace the Character

with 0 Comment
clear
echo "Count and Replace the character"
echo "---------------------------------------"
echo "Enter The String"
read string
d='echo $string|wc -c'
d='expr $d -l'
echo "Total No.of Character in a String:"$d
echo "Enter the string to be searched"
read str
echo "Enter Which character should be replaced"
read r
count=0
i=1
newstr=""
while[$i -le $d]
do
s='expr $string|cut -c $i'
if[$s=$str]
then
newstr='echo $newstr$r'
count='expr $count+1'
else
newstr='echo $newstr$s'
fi
i='expr $i+1'
done
if[$count=0]
then
echo "$str is not present in the String" $string
else
echo "$str is present in the String" $string
echo "The Original String is" $string
echo "The New String is" $newstr
fi

-------------
OUTPUT:
-------------
Count and Replace the Charcter
--------------------------------------
Enter the String
Welcoke

Total No of Character in a String:7

Enter The String to be Searched
k

Enter Which Character should be Replaced
m
k is present in the string welcoke

The Original String is Welcoke

The New String is welcome

Unix and Shell Programming - Employee Salary Details

with 0 Comment
clear
echo "Employee Details"
echo "---------------------"
echo "Enter the emplyee name"
read name
echo "Enter the emplyee number"
read no
echo "Enter the designation"
read des
echo "Enter the basic pay""
read bpay
echo
hra='echo "$bpay*10/100"|bc'
da='expr $bpay*15/100|bc'
lic='expr $bpay*5/100|bc'
pf='expr $bpay*3/100|bc'
gp='echo "$hra+$da+$bpay"|bc'
np='echo "$gp-($lic+$pf)"|bc'
echo "Employee Details"
echo "---------------------"
echo "Employee Name:"$name
echo "Employee Number:"$no
echo "Designation:"$des
echo "Basic pay:"$bpay
echo "HRA:"$hra
echo "DA:"$da
echo "LIC:"$lic
echo "PF:"$pf
echo "Gross Pay:"$gp
echo "Net Pay:"$np

-------------
OUTPUT:
------------
Employee Details
---------------------
Enter the employee name
Ashok

Enter the employee number
13

Enter the designation
labour

Enter the basic pay
8000

Employee Details
---------------------
Employee Name: Ashok
Employee Number:13
Designation    :labour
Basic Pay      :8000
HRA             :800
DA               :1200
LIC               :400
PF                :240
Gross Pay      :10000
Net Pay          :9360

Unix and Shell Programming - Sorting and Merging Files

with 0 Comment
clear
echo "Sorting and Merging Files"
echo "--------------------------------"
echo
while true
do
echo "Menu"
echo "------"
echo
echo "1.Sorting a File"
echo
echo "2.Merging a Two File"
echo
echo "3.Exit"
echo
echo "Enter your choice"
read c
case $c in

1)
echo  "Sorting a file"
echo  "----------------"
ls
echo
echo "Enter the file"
read f
echo "Before sorted"
echo "----------------"
echo
cat $f
echo "After Sorted"
echo "---------------"
sort -o f $f
cat f
echo
;;

2)
echo "Merging a two file"
echo "----------------------"
echo "Enter the first file name"
read f
echo "Enter the second file name"
read f1
echo "Before Sorted"
echo "----------------"
echo
echo "Contents of First file"
echo "-------------------------"
cat $f
echo "Contents of Second file"
echo "----------------------------"
cat $f1
echo
echo "After Sorted"
echo "---------------"
sort -o f $f
sort -o f1 $f1
echo "Sorted first file"
echo "------------------"
cat f
echo "Sorted Second file"
echo "----------------------"
cat f1
echo "After merging a two sorted files"
echo "--------------------------------------"
sort -m -o ans f f1
echo
cat ans
echo "End of sorting and merging file"
;;

3)
exit
esac
done

--------------
OUTPUT:
-------------
Sorting and Merging Files:
----------------------

Menu
-------
1.Sorting a File
2.Merging a two file
3.Exit

Enter our choice
1
Sorting a file
----------------
1    count1.sh    f    indu   priya3   selvi   trans.sh
a     count.sh     f1   Indu  ram   semi.sh  tr.sh
a2   d2    f3    mano    re  sort1.sh     vidhya

Enter the file
cmp

Before Sorted
-----------------
Madurai
Thrichy
Chennai
delhi
banglore

After Sorted
---------------
banglore
chennai
delhi
madurai
thrichy

Enter our choice
2

Merging a two file
-----------------------
Enter the first file name
cmp
Enter the second file name
cmp1
Before Sorted
-----------------
Contents of First File
-------------------------
Madurai
thrichy
chennai
delhi
banglore

Contents of Second file
----------------------------
madurai
thrichy
chennai
delhi
banglore

After Sorted
---------------
Sorted First File
-------------------
banglore
chennai
delhi
madurai
thrichy

Sorted Second file
----------------------
banglove
chennai
delhi
madurai
thrichy

After merging a two sorted files
--------------------------------------
banglore
banglore
chennai
chennai
delhi
delhi
madurai
madurai
thrichy
thrichy

End of Sorting and merging file

Enter our choice
3

Unix and Shell Programming - illustrate WC Commands

with 0 Comment
while true
do
echo "MENU"
echo "---------"
echo "1.Number of users"
echo
echo "2.Number of lines words and chracters"
echo
echo 3.Exit
echo
echo Enter your choice
read c
case $c in

1)
echo "Number of users"
echo "--------------------"
echo
who|wc -l
echo
echo
;;

2)
echo "Number of lines words and characters in a File"
echo "--------------------------------------------------------"
echo
ls
echo "Enter the file name"
read f1
if test -f $f1
then
echo
echo "Content of the File"
echo "----------------------"
cat $f1
echo
echo "Number of lines"
wc -l<$f1
echo
echo "Number of Words"
wc -w<$f1
echo
echo "Number of Characters"
wc -c<$f1
echo
else
echo File not Exists.
fi
;;


3)
echo Exit
echo ---
exit
esac
done

-------------
OUTPUT:
-------------
MENU
--------
1.Number of users
2.Number of lines words and characters
3.Exit

Enter your Choice
1
Number of users
--------------------
33


Enter your choice
2

Number of lines words and charcters in a File
-------------------------------------------------------
1   count1.sh   f   indu    priya3   selvi   trans.sh
a   count.sh     f1  Indu   ram     semi.sh  tr.sh
a2   d2        f3    mano    re   sort1 .sh   vidhya

Enter your file name
cmp

Content of the File
----------------------
madurai
thrichy
chennai
delhi
banglore

Number of lines
5
Number of Words
5
Number of Characters
39
---------------------------
Enter your choice
3
Exit

Unix and Shell Programming - Database Manipulation

with 0 Comment
clear
echo "Database Manipulation"
echo "----------------------------"
echo "Database Creation"
echo "----------------------"
echo "Enter the File name"
read fn
echo "Content of the File"
echo "-----------------------"
cat $fn
while true
do
echo "Menu"
echo "-----"
echo "1.Cut"
echo "2.Paste"
echo "3.Sort"
echo "4.Merge"
echo "5.Exit"
echo "Enter our choice"
read ch
cae $ch in
1)
echo "Cut Command"
echo "------------"
echo "Cut Based on the File Position"
cut -c 1-3,20-$fn>name2
cat name2
;;

2)
echo "Paste Command"
echo "-------------------"
cat $fn
echo "Enter the field position -1"
read p1
cut -f $p1 $fn>name3
echo
echo "Enter the field position -2"
read p2
echo
cut -f $p2 $fn>name4
echo
echo "Pasting"
echo "--------"
paste name3 name4>name5
cat name5
;;


3)
echo "Sort Command"
echo "------------------"
echo "Before Sorting"
echo "------------------"
cat name2
echo
echo "After Sorting"
echo "----------------"
sort name2>sname2
cat sname2
;;

4)
echo "Merge File"
echo "-------------"
echo "Sorted File1"
echo "---------------"
cat sname2
echo "Sorted File2"
echo "---------------"
sort name4>sname4
cat sname4
echo "Merge Sorting"
echo "-----------------"
sort -m sname2 sname4
;;

5)
echo "No Choice"
exit
;;
esac
done

----------
Output:
----------
Datbase Manipulation
--------------------------
Databsae Creation
----------------------
Enter the file name
cmp

Content of the file
----------------------
madurai
thrichy
chennai
delhi
bangalore

Menu
-------
1.Cut
2.Paste
3.Sort
4.Merge
5.Exit

Enter our Choice
1

Cut Command
-----------------
Cut Based on the file position

mad
thr
che
del
ban

Enter our choice
2

Paste Command
-------------------
madurai
thrichy
chennai
delhi
banglore

Enter the field position -1
2

Enter the field position -2
5

Pasting
---------
madurai  madurai
thrichy    thrichy
chennai   chennai
delhi       delhi
banglore  banglore

Enter our choice
3
Sort Command
------------------
Before Sorting
------------------
mad
thr
che
del
ban

After Sorting
----------------
ban
che
del
mad
thr

Enter our choice
4

Merge File
-------------
Sorted File1
--------------
ban
che
del
mad
thr

Sorted file2
--------------
banglore
chennai
delhi
madurai
thrichy

Merge Sorting
-----------------
ban
banglore
che
chennai
del
delhi
mad
madurai
thr
thrichy

Enter our choice
5
No Choice

Unix and Shell Programming - File Access Permission

with 0 Comment
clear
while true
do
echo
echo "File Access Permission"
echo "--------------------"
echo "1.Symbolic Mode"
echo "2.Absolute Mode"
echo "3.Exit"
echo "Enter your choice"
read n
case $n in

1)
echo "Symbolic Mode"
echo "-------------"
echo "Enter your File name"
read fn
if test -f $fn
then
echo "File is Present"
ls -l $fn
echo "Enter your Symbolic Entries(u,g,o)"
read se
echo
echo "Symbolic Operation(+,-,=)"
read so
echo
echo "Symbolic Permission(r,w,x)"
read sp
chmod $se$so$sp $fn
ls -l $fn
else
echo "File is Not Present"
fi
;;

2)
echo "Absolute Mode"
echo "------------"
echo "Enter the File Name"
read fn
if test -f $fn
then
echo "File is Present"ls -l $fn
echo "1.Execute"
echo "2.Write"
echo "3.Write && Execute"
echo "4.Read"
echo "5.Read && Execute"
echo "6.Read && Write"
echo "7.Read,Write && Execute"
echo "Enter your Rights for Users"
read u
echo "Enter the Rights for group"
read g
echo "Enter the Rights for others"
read o
chmod $u$g$o $fn
ls -l $fn
else
echo "File is Not Present"
fi
;;

3)
echo "Exit"
exit
;;
esac
done

-------------
OUTPUT:
-------------
File Access Permission
----------------------------
1.Symbolic Mode
2.Absolute Mode
3.Exit

Enter your choice
1

Symbolic Mode
-------------------
Enter the File Name
cmp1

File is Present

-rw-rw-r--     1 smca13  smca13    39 Aug 25  13:47 cmp1

Enter the Symbolic Entries(u,g,o)
u

Symbolic Operation(+,-,=)
+

Symbolic Permission(r,w,x)
x
-rwxrw-r--   1 smca13 smca13   39 Aug 25  13:47  cmp1

Enter your choice
2

Absolute Mode
------------------
Enter the File Name
cmp

File is Present
-w-r--r-- 1 smca13    smca13    39Aug31  13:48 cmp
1.Execute
2.Write
3.Write && Execute
4.Read
5.Read && Execute
6.Read && Write
7.Read,Write && Execute

Enter the Rights for Users
5

Enter the Rights for Group
3

Enter the Rights for Others
2

-r-x-wx-w-  1 smca13   smca13     39 Aug 31    13:48 cmp

Enter your choice
3
Exit

Unix and Shell Programming - Comparing Two Files

with 0 Comment
clear
ch=1
while true
do
echo "MENU"
echo "-----"
echo "1.Comparing two files"
echo "2.Difference between two files"
echo "3.Common between two files"
echo "4.Exit"
echo "Enter our choice"
read ch
case $ch in

1)
echo "Compare two files"
echo "---------------"
echo "Enter the first file name"
read r1
echo "Content of the file"$r1
cat $r1
echo "Enter the second file name"
read r2
echo "Content of the file"$r2
cat $r2
echo "Compare two files"
echo "---------------"
cmp $r1 $r2
;;

2)
echo "Difference between two files"
echo "------------------------"
echo "Enter the first file name"
read d1
echo "Content of the file"$d1
cat $d1
echo "Enter the second file name"
read d2
echo "Content of the file"$d2
cat $d2
echo "Differ two files"
echo "------------"
diff $d1 $d2
;;

3)
echo "Common between two files"
echo "-----------------------"
echo "Enter the first file name"
read c1
echo "Content of the file"$c1
cat $c1
echo "Enter the second file name"
read c2
echo "Content of the file"$c2
cat $c2
echo "Common two files"
echo "---------------"
comm $c1 $c2
;;

4)
echo "Exit"
echo "---"
exit
;;
esac
done

-------------
OUTPUT:
-------------
Menu
-------
1.Compare two files
2.Difference between two files
3.Common between two files
4.Exit

Enter our choice
1
Compare two files
----------------------
Enter the first file name
cmp

Content of the file :cmp

madurai
thrichy
mysore
delhi

Enter the second file name
cmp1

Content of the file :cmp1
madurai
thrichy
chennai
delhi
banglore

Compare two files
----------------------
cmp cmp1 differ:byte 5,line 1

Enter our choice
2
Difference between two files
-----------------------------------
Enter the first file name
cmp

Content of the file:cmp
madurai
thrichy
mysore
delhi

Enter your second file name
cmp1

Content of the file :cmp1
madurai
thrichy
chennai
delhi
banglore

Differ two files
------------------
1c1
<madurai
---
>madurai
3c3
<mysore
---
>chennai
4a5
>banglore

Enter our choice
3
Common between two files
---------------------------------
Enter the first file name
cmp

Content of the file :cmp
madurai
thrichy
mysore
delhi

Enter the second file name
cmp1

Content of the file:cmp1
madurai
thrichy
chennai
delhi
banglore

Common Two Files
------------------------
                    madurai
madurai
                                       Thrichy
                  Chennai
                  delhi
                  banglore
mysore
delhi

Enter your choice
4
Exit   

Unix and Shell Programming - File Operation

with 0 Comment
ch=1
while true
do
echo "Menu"
echo "-----"
echo "1.Create a file"
echo "2.Append a file"
echo "3.Concatenation"
echo "4.Display a file"
echo "5.Copy a file"
echo "6.Move a file"
echo "7.Split a file"
echo "8.Remove a file"
echo "9.Exit"
echo "Enter your choice"
read ch
case $ch in
1)
echo "Create a file"
echo "-----------"
echo "Enter your file name"
read f1
if test -f $f1
then
echo "File already exists"
ls
else
echo "File Created"
echo "Enter your contents of the file"
cat>$f1
echo "File created with the name"$f1
ls
fi
;;

2)
echo "Append a file"
echo "-----------"
echo "Enter your first file name"
read a
echo "Enter your second file name"
read b
echo "Contents of the first file"
cat $a
echo "Contents of the second file"
cat $b
cat $a>>$b
echo "Process is Over"
echo "After append :"$b
echo "Contents of the append file"
cat $b
echo "file is not present"
;;

3)
echo "Concatenation of a file"
echo "-------------------"
echo "Enter the first file name"
read a
echo "Enter the second file name"
read b
echo "Before Concatenation"
echo "------------------"
echo "Content of first file"
cat $a
echo "Content of second file"
cat $b
echo "After Concatenation"
echo "-----------------"
cat $a $b
;;

4)
echo "Display a file"
echo "-----------"
echo "Enter the file name"
read f
if test -f $f
then
cat $f
else
echo "File not exists"
fi
;;

5)
echo "Copy of file"
echo "----------"
echo "Enter the file name"
read f1
echo "Enter the second file name to be copied"
read f2
if test -f $f1
then
cp $f1 $f2
echo "Content of the Original file"
cat $f1
echo "Content of the Copied file"
cat $f2
else
echo "File not exists"
fi
;;

6)
echo "Move a file"
echo "---------"
echo "Enter the source file"
read f
echo "Enter the destination file"
read f1
if test -f $f
then
mv $f $f1

echo "Content of the moved file"
cat $f1
ls
else
echo "File does not exists"
fi
;;

7)
echo "Split a file"
echo "---------"
echo "Enter the file name"
read a
if test -f $a
then
split -2 $a
echo "File Splitted"
ls xa*
else
echo "File not exists"
fi
;;

8)
echo "Remove a file"
echo "------------"
echo "Enter the file name"
read b
if test -f $b
then
echo "File already exists"
echo "Contents of $b file"
cat $b
rm $b
echo "File removed"
else
echo "File not found"
fi
;;

9)
echo "Exit"
exit
;;
esac
done

------------
OUTPUT:
------------
Menu
-------
1.Create a file
2.Append a file
3.Concatenation
4.Display a file
5.Copy a file
6.Move a file
7.Split a file
8.Remove a file
9.Exit

Enter your choice
1

Create a file
---------------
Enter your file name
file1

File created

Enter the contents of the file
hai
hello
welcome to all

Enter your choice
2

Append a file
-----------------
Enter the first file name
file1

Enter the second file name
aa1

Contents of the first file
-----------------------------
hai
hello
welcome to all

Contents of the second file
---------------------------------
have a nice day
god
priya
hai
hello
welcome to all

Process is Over
After append:aa1

Contents of the append file
--------------------------------
have a nice day
god
priya
hai
hello
welcome to all
hai
hello
welcome to all
file is not present

Enter your choice
3

Concatenation of a file
---------------------------
Enter the first file name
file1

Enter the second file name
aa1

Before Concatenation
--------------------------
Content of first file
-----------------------
hai
hello
welcome to all

Content of second file
--------------------------
have a nice day
god
priya
hai
hello
welcome to all

After Concatenation
------------------------
hai
hello
welcome to all
have a nice day
god
priya
hai
hello
welcome to all

Enter your choice
4

Display a file
----------------
Enter the file name
aa1

have a nice day
god
priya
hai
hello
welcome to all


Enter your choice
5

Copy a file
-------------
Enter the file name
fil1

Enter the second file name to be copied
r1

Content of the Original file
--------------------------------
hai
hello
welcome to all

Content of the Copied file
-------------------------------
hai
hello
welcome to all

Enter your choice
6

Move a File
--------------
Enter the source file
fil1

Enter the destination file
r1

Content of the moved file
-------------------------------
hai
hello
welcome to all

1  d2  friends  navani  rithika  sasa  srp1
a  dad  fruits   p3        rk3    sasaa  srp2
a2 dddd  fsdg   p4      rk4    sasas  sss

Enter your choice
7

Split a file
------------
Enter the file name
r1

File Splitted
--------------
xaa  xab  xac  xad

Enter your choice
8

Remove a file
-----------------
Enter the file name
r1
file already exists

Contents of r1 file
hai
hello
welcome to all

File Removed

Enter your choice
9
Exit

Unix and Shell Programming - Directory Operations

with 0 Comment
clear
ch=1
while true
do
echo
echo "Directory Operation"
echo "************"
echo "1.Directory Creation"
echo "2.Remove Directory"
echo "3.Copy file to directory"
echo "4.Move file to directory"
echo "5.Change Directory"
echo "6.Exit"
echo "Enter your choice"
read ch
case $ch in
1)
echo "Directory Creation"
echo "***********"
echo
echo "Enter the directory name"
read  m
if test -d $m
then
echo "Directory already exists"
else
mkdir $m
ls -x
echo "Directory Created"
fi
;;

2)
echo "Remove directory"
echo "***********"
echo
echo "Enter your directory"
read m
if test -d $m
then
cd $m
ls -x
rm *
cd
cd
rmdir $m
echo "Directory Removed"
else
echo "Directory not found"
fi
;;

3)
echo "Copy a file to directory"
echo "*************"
echo
echo "Enter your file name"
read f
if test -f $f
then
echo "File already exists"
echo "Enter the destination directory name:"
read ds
if test -d $ds
then
echo "Directory already exists"
cp $f $ds
echo "Copied successfully"
else
echo "Directory not exists"
fi
else
echo "File not present"
fi
;;

4)
echo "Move a file to directory"
echo "**************"
echo
echo "Enter the file name"
read f
if test -f $f
then
echo "File already exists"
echo "Enter the destination directory"
read ds
if test -d $ds
then
echo "Directory already exists"
mv $f $ds
echo "Moved successfully"
else
echo "Directory not exists"
fi
else
echo "File not present"
fi
;;

5)
echo "Change Directory"
echo "**********"
echo
echo "Enter your directory name"
read n
if test -d $n
then
cd $n
ls
echo "Enter your file name to be view"
read n
echo "The contents of the file"
echo
cat $n
cd
else
echo "The Directory not exists"
fi
;;

6)
echo "Exit"
exit
;;
esac
done

----------
Output:
*******
Directory Operation
****************
1.Directory Creation
2.Remove Directory
3.Copy file to directory
4.Move file to directory
5.Change directory
6.Exit

Enter your choice
1
Directory Creation
***********
Enter your directory name
varshini

a      aaaa    alpha1.sh    alpha1.sh    alpha.sh    anbu  a.out 
asd  ball   dad  dddd  deepa    depa   dhars
do.sh   durga    ebill.sh   employee   f3   fdf  friends

Directory Created

Enter your choice
2
Remove directory
***********
Enter your directory
anbu
surya

Directory Removed

Enter your choice
3
Copy a file to directory
**************
Enter your file name
fdf
File already exists

Enter your destination directory name:
depa
Directory already exists

Copied successfully

Enter your choice
4
Move a file to directory
**************
Enter the file name
fdf
File already exists

Enter the destination directory
deepa
Directory already exists

Moved Successfully

Enter your choice
5

Change Directory
***********
Enter the directory name
dad
add dsa rs

Enter the file name to be view
dsa

The contents of the file
priya
raji
hello
hai
welcome

Enter your choice
6
Exit

Unix and Shell Programming - Basic Unix Commands

with 0 Comment
While true
do
echo “Basic Unix Commands”
echo “*******************”
echo “1.Present Working Directory”
echo “2.User for all working directory”
echo “3.User for current working directory”
echo “4.Display Long Listing”
echo “5.Display Long Listing for column wise”
echo “6.Display Long Listing for row wise”
echo “7.Display Current Date”
echo “8.Display Calendar”
echo “9.Display Unix Details”
echo “10.Move the Cursor Position”
echo “11.Exit”
echo “Enter your Choice”
read n
case $n in

1)
echo “Present working directory”
echo “**********************”
echo
pwd
;;

2)
echo “User for all Working Directory”
echo “*************************”
echo
who
;;

3)
echo “User for Current Directory”
echo “**********************”
echo
who am i
;;

4)
echo “Display Long Listing”
echo “*****************”
echo
ls
ls -l
;;

5)
echo "Display Long Listing Column Wise"
echo "********************"
echo
ls -c
;;

6)
echo "Display Long Listing Row wise"
echo "******************"
echo
ls -x
;;

7)
echo "Display Current Date"
echo "************"
echo
date
;;

8)
echo "Display Calendar"
echo "**********"
echo
read m
read y
cal $m $y
;;

9)
echo "Display Unix Details"
echo "************"
echo
uname
uname -a
;;

10)
echo "Move the Cursor Position"
echo "***************"
echo
echo "Enter the row & column"
read r
read c
tput cup $r $c
echo "Welcome To All"
;;

11)
echo "Exit"
exit
;;
esac
done

---------
Output :
******
Basic Unix Commands
*******************
1.Present Working Directory
2.User for all working directory
3.User for Current working Directory
4.Display Long Listing
5.Display Long Listing for Column wise
6.Display Long Listing for row wise
7.Display Current date
8.Display Calendar
9.Display Unix Details
10.Move the Cursor Position
11.Exit

Enter your Choice
1
Present Working Directory
**********************
/home/smca13

Enter your Choice
2
User for all Working Directory
*************************
smca21 pts/2          Aug 1       14:27(192.168.1.121)
smca20 pts/6          Aug 1       14:27(192.168.1.120)
smca17 pts/3          Aug 1       14:27(192.168.1.137)
smca19 pts/9          Aug 1       14:27(192.168.1.119)

Enter your choice
3
User for Current Directory
**********************
smca13 pts/8          Aug 1       14:27(192.168.1.133)


Enter your choice
4
Display Long Listing
******************
a   depa   guna   muruges   sample1.sh   sasi    test1
aaaa   dhars    hari    navani    sample2.sh   sathya  vani
total 308
drwxrwxr-x   2 smca13   smca13   4096  Jul 26 12:59 aaaa
-rw-rw-r--   1  smca13  smca13   2 Jul 16 15:46 alph1.sh

Enter your choice
5
Display Long Listing Column wise
*****************************
sample.sh   dhars   siva   sasi   priya.sh   friends  priya   muru
do.sh   a   vidhya1   raji   sam.sh   selvi   fruits  sathya


Enter your choice
6
Display Long Listing Row wise
**************************
a    aaaa    alph1.sh   alpha1.sh    alpha.sh    anbu   a.out
asd   ball dad dddd deepa depa dhars
do.sh durga ebill.sh employee f3 fdf friends

Enter your choice
7
Display Current Date
******************
Wed Aug  1  16:09:18  IST 2012


Enter your choice
8
Display Calendar
**************
12
2012


December 2012
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 31


Enter your choice
9
Display Unix Details
*****************
Linux
Linux SRNM 2.4.21-4.EL #1 Fri Oct 3 18:13:58 EDT 2003 i686 i686
i386 GNU/Linux


Enter your choice
10

Move the cursor position
********************
Enter your row & column
100
5
   Welcome To All

Enter your choice
11
Exit
Powered by Blogger.