User talk:Nandu1000

Case Study for shell scripting Write a shell which accepts a flat file, interpret the type of file and do the required operation. Use functions for every operation Operations include:- - Adding new employees to the master employee file with info from a file - Marking employee status as “quit” in master employee file with info from a file i.e. employees who have quit the organization. - Update employee info from master employee file with info from a file - Identify the location of the employee and add or update or delete info from the location file also - In case of transfer move info from one location file to the other location file also Other features:- - Increment the days of employment in the corresponding field in the employee file everyday - Generate a report for the admin with the following info a) New employees b) Transferred employees c) Employees who have quit - Check before processing for the availability of the file in the directory Can include:- - Employee id can be generated, instead of being a part of the file - Can have separate files for all the employees and update info in those files also. Useful Commands:- 1) read 2) sed 3) awk 4) for, while, if, case 5) test 6) Redirection operators 7) Wildcard characters 8) grep Master employee file:- Emp.no name desgn. Project location status Note:- Make suitable assumptions as needed.

Case Study for shell scripting Write a shell which accepts a flat file, interpret the type of file and do the required operation. Use functions for every operation Operations include:- - Adding new employees to the master employee file with info from a file - Marking employee status as “quit” in master employee file with info from a file i.e. employees who have quit the organization. - Update employee info from master employee file with info from a file - Identify the location of the employee and add or update or delete info from the location file also - In case of transfer move info from one location file to the other location file also Other features:- - Increment the days of employment in the corresponding field in the employee file everyday - Generate a report for the admin with the following info a) New employees b) Transferred employees c) Employees who have quit - Check before processing for the availability of the file in the directory Can include:- - Employee id can be generated, instead of being a part of the file - Can have separate files for all the employees and update info in those files also. Useful Commands:- 1) read 2) sed 3) awk 4) for, while, if, case 5) test 6) Redirection operators 7) Wildcard characters 8) grep Master employee file:- Emp.no name desgn. Project location status Note:- Make suitable assumptions as needed.

employeeid=`wc -l < masterfile` for i in {1..100} do    #grep "$i" newemployees > stringfile #sed -n '/^/$i*$/p' newemployees > stringfile awk -F"|" -v pin=$i 'NR == pin {print}' newemployees > stringfile #echo "Displaying String file" #cat stringfile if [ $? = 0 ]      then #cat stringfile index=1 temp=`expr $employeeid + $index` employeeid=$temp #echo "Employee id =$employeeid" awk -F"|" -v a=$employeeid '{printf "%d|%-25s|%-11s|%-12s|%-9s|%-8s|001|",a,$2,$3,$4,$5,$6}' stringfile > tempfile #cat tempfile cat tempfile >> tempmasterfile echo -e "\n" >> tempmasterfile fi done sed '/^[	]*$/d' tempmasterfile > tempfile cat tempfile > tempmasterfile
 * 1) index=1
 * 2) cat newemployee
 * 3) echo "Check point1"
 * 4) wc -l newemployee
 * 5) echo "Check point 2"
 * 1) echo "Check point 3"
 * 2) echo "Record Count = $recordcount"
 * 3) echo "Starting for loop"
 * 4) lines=`cat newemployee`
 * 5) set $lines

for n in `cut -d ":" -f 1 quitfile` do str=`grep "^$n" quitfile |cut -d "|" -f 1` grep "^$n" quitfile |cut -d ":" -f 1,5 > f1 echo $str abc=$srr grep "$abc" masterfile done
 * 1) if test `grep "^$n|" quitfile | wc -l` -ne 0
 * 2) then
 * fi

01|Gunpreet Singh Kohli    |C.E.O      |Banking     |Delhi    |Active  |104| 02|Harpreet Singh          |Manager    |Telecom     |Mumbai   |Active  |185| 03|Digvijay Singh Sengar   |Sales      |Govt        |Chennai  |Active  |494| 04|Lalu Yadav              |Sales      |Telecom     |Delhi    |Active  |228| 05|Baby Sharma             |Manager    |Banking     |Mumbai   |Acitve  |572| 06|Arpit Thakur            |Chairman   |Insurance   |Kanpur   |Active  |024| 07|Sonal Rajab             |Production |Insurance   |Delhi    |Active  |018| 08|Altaf Sharma            |Trainee    |Govt        |Mumbai   |Active  |057| 09|M.D Aziz                |Sales      |Insurance   |Mumbai   |Active  |632| 10|Shahrukh Khan           |Production |Banking     |Delhi    |Active  |036| 11|Sanjay Mishra           |Manager    |Telecom     |Mumbai   |Active  |016| 12|Preeti Bedi             |Trainee    |Govt        |Kanpur   |Active  |342| 13|Pappu Khan              |Sales      |Telecom     |Chennai  |Active  |634| 14|Divya Soni              |Manager    |Bannking    |Delhi    |Active  |077| 15|Johny Singh             |Trainee    |Banking     |Kanpur   |Active  |003| 16|Silvia Sharma           |Production |Govt        |Kanpur   |Active  |026| 17|Mark Mohomad            |Production |Govt        |Delhi    |Active  |724| 18|Ankur Anderson          |Trainee    |Telecom     |Chennai  |Active  |062| 19|Devi Gilchrist          |Sales      |Banking     |Mumbai   |Active  |032| 20|Rajat John Singh        |Manager    |Telecom     |Chennai  |Acitve  |042|

a1
01|Gunpreet Singh Kohli    |C.E.O      |Banking     |Delhi    |Active  |104| 02|Harpreet Singh          |Manager    |Telecom     |Mumbai   |Active  |185| 03|Digvijay Singh Sengar   |Sales      |Govt        |Chennai  |Active  |494| 04|Lalu Yadav              |Sales      |Telecom     |Delhi    |Active  |228| 05|Baby Sharma             |Manager    |Banking     |Mumbai   |Acitve  |572| 06|Arpit Thakur            |Chairman   |Insurance   |Kanpur   |Active  |024| 07|Sonal Rajab             |Production |Insurance   |Delhi    |Active  |018| 08|Altaf Sharma            |Trainee    |Govt        |Mumbai   |Active  |057| 09|M.D Aziz                |Sales      |Insurance   |Mumbai   |Active  |632| 10|Shahrukh Khan           |Production |Banking     |Delhi    |Active  |036| 11|Sanjay Mishra           |Manager    |Telecom     |Mumbai   |Active  |016| 12|Preeti Bedi             |Trainee    |Govt        |Kanpur   |Active  |342| 13|Pappu Khan              |Sales      |Telecom     |Chennai  |Active  |634| 14|Divya Soni              |Manager    |Bannking    |Delhi    |Active  |077| 15|Johny Singh             |Trainee    |Banking     |Kanpur   |Active  |003| 16|Silvia Sharma           |Production |Govt        |Kanpur   |Active  |026| 17|Mark Mohomad            |Production |Govt        |Delhi    |Active  |724| 18|Ankur Anderson          |Trainee    |Telecom     |Chennai  |Active  |062| 19|Devi Gilchrist          |Sales      |Banking     |Mumbai   |Active  |032| 20|Rajat John Singh        |Manager    |Telecom     |Chennai  |Acitve  |042|

b1
employeeid=`wc -l < masterfile` for i in {1..100} do    #grep "$i" newemployees > stringfile #sed -n '/^/$i*$/p' newemployees > stringfile awk -F"|" -v pin=$i 'NR == pin {print}' newemployees > stringfile #echo "Displaying String file" #cat stringfile if [ $? = 0 ]      then #cat stringfile index=1 temp=`expr $employeeid + $index` employeeid=$temp #echo "Employee id =$employeeid" awk -F"|" -v a=$employeeid '{printf "%d|%-25s|%-11s|%-12s|%-9s|%-8s|001|",a,$2,$3,$4,$5,$6}' stringfile > tempfile #cat tempfile cat tempfile >> tempmasterfile echo -e "\n" >> tempmasterfile fi done sed '/^[	]*$/d' tempmasterfile > tempfile cat tempfile > tempmasterfile
 * 1) index=1
 * 2) cat newemployee
 * 3) echo "Check point1"
 * 4) wc -l newemployee
 * 5) echo "Check point 2"
 * 1) echo "Check point 3"
 * 2) echo "Record Count = $recordcount"
 * 3) echo "Starting for loop"
 * 4) lines=`cat newemployee`
 * 5) set $lines

addemployee
updatedinfo

for i in `cut -d"|" -f 1 updatedfile` do echo " value of $i"; val=`grep "^$i|" masterfile | wc -l` if test $val -eq 1 then grep -v "^$i|" masterfile > unupdatedrows grep "^$i|" updatedfile >> unupdatedrows sort -n unupdatedrows > masterfile fi done cat masterfil:

updatefile

02|Harpreet Singh |Senior Manager | Banking |Delhi|Active |189| 04|Lalu Yadav |Sales |Insurance |Delhi|Active |318| 10|Shahrukh Khan |ASE |Banking |Delhi|Active |036| 18|Ankur Anderson |Trainee |Telecom |Kanpur|Active |100|

unupdatedrows

01|Gunpreet Singh Kohli    |C.E.O      |Banking     |Delhi    |Quit  |104| 02|Harpreet Singh          |Sr Manager |Banking     |Delhi    |Quit  |189| 03|Digvijay Singh Sengar   |Sales      |Govt        |Chennai  |Quit  |494| 04|Lalu Yadav |Sales |Insurance |Delhi|Quit |318| 05|Baby Sharma             |Manager    |Banking     |Mumbai   |Acitve  |572| 06|Arpit Thakur            |Chairman   |Insurance   |Kanpur   |Quit  |024| 07|Sonal Rajab             |Production |Insurance   |Delhi    |Quit  |018| 08|Altaf Sharma            |Trainee    |Govt        |Mumbai   |Quit  |057| 09|M.D Aziz                |Sales      |Insurance   |Mumbai   |Quit  |632| 10|Shahrukh Khan           |ASE        |Banking     |Delhi    |Quit  |036| 11|Sanjay Mishra           |Manager    |Telecom     |Mumbai   |Quit  |016| 12|Preeti Bedi             |Trainee    |Govt        |Kanpur   |Quit  |342| 13|Pappu Khan              |Sales      |Telecom     |Chennai  |Quit  |634| 14|Divya Soni              |Manager    |Bannking    |Delhi    |Quit  |077| 15|Johny Singh             |Trainee    |Banking     |Kanpur   |Quit  |003| 16|Silvia Sharma           |Production |Govt        |Kanpur   |Quit  |026| 17|Mark Mohomad            |Production |Govt        |Delhi    |Quit  |724| 19|Devi Gilchrist          |Sales      |Banking     |Mumbai   |Quit  |032| 20|Rajat John Singh        |Manager    |Telecom     |Chennai  |Acitve  |042| 18|Ankur Anderson |Trainee |Telecom |Kanpur|Quit |100|

transfers

for i in {1..7} do echo "i=$i" awk -F"|" -v var=$i ' NR == var { print }' location > tempfile cat tempfile echo "Check point 1" cut -d"|" -f1 tempfile > singleid empid=`cat singleid` echo "id = $empid" cut -d"|" -f2 tempfile > oldlocation old=`cat oldlocation` echo "old loc =$old" cut -d"|" -f3 tempfile > newlocation new=`cat newlocation` echo "new loc=$new" if [ -e $old -a -e $new ] then grep "^$empid" $old echo "\$ ?=$?" if [ $? -eq 0 ] then grep "^$empid" $old > appendrecord echo "Echoing append File" cat appendrecord awk -F"|" -v loc=$new '{ printf "%d|%s|%s|%s|%s|%s|",$1,$2,$3,$4,loc,$6 }' appendrecord > rearrangement echo -e "\n" >> $new cat appendrecord >> $new fi

fi done

transfer

for i in {1..7} do echo "i=$i" awk -F"|" -v var=$i ' NR == var { print }' location > tempfile cat tempfile cut -d"|" -f1 > singleid empid=`cat singleid` cut -d"|" -f2 > oldlocation old=`cat oldlocation` cut -d"|" -f3 > newlocation new=`cat newlocation` grep "^$empid" delhi > temprecord

done

tempmasterfile

01|Gunpreet Singh Kohli|C.E.O|Banking|Delhi|Quit|104| 02|Harpreet Singh|Sr Manager |Banking|Delhi|Quit|189| 03|DigviJay Singh Sengar|Sales|Govt |Chennai|Quit|494| 04|Lalu Yadav |Sales |Insurance|Delhi|Quit|318| 05|Baby Sharma|Manager|Banking |Mumbai|Acitve|572| 06|Arpit Thakur|Chairman|Insurance|Kanpur|Quit|024| 07|Sonal Rajab|Production|Insurance|Delhi|Quit |018| 08|Altaf Sharma|Trainee|Govt|Mumbai|Quit|057| 09|M.D Aziz|Sales|Insurance|Mumbai|Quit|632| 10|Shahrukh Khan|ASE|Banking|Delhi|Quit|036| 11|Sanjay Mishra|Manager|Telecom|Mumbai|Quit |016| 12|Preeti Bedi|Trainee|Govt|Kanpur|Quit|342| 13|Pappu Khan|Sales|Telecom|Chennai|Quit|634| 14|Divya Soni|Manager|Bannking|Delhi|Quit|077| 15|Johny Singh|Trainee|Banking|Kanpur|Quit|003| 16|Silvia Sharma|Production|Govt|Kanpur|Quit|026| 17|Mark Mohomad|Production|Govt|Delhi |Quit|724| 18|Ankur Anderson|Trainee|Telecom|Kanpur|Quit|100| 19|Devi Gilchrist|Sales|Banking|Mumbai |Quit|032| 20|Rajat John Singh|Manager|Telecom |Chennai|Acitve|042| 21|Chandra Mohan|Manager|Banking|Delhi|Active| 22|Dipanshu Wahi|Sales|Telecom|Mumbai|Active| 23|Gyanendra|Trainee|Govt|Kanpur|Active| 24|Suneeta|Production |Insurence|Chennai|Active| 25|Laxman Singh|Trainee|Banking|Kanpur|Active| 26|Laxmi Kant|manager|Telecom|Mumbai|Active| 27|Kuldeep Singh|Production|Govt|Chennai|Active| 28|Shyam|Sales|Insurence|Mumbai|Active| 29|Shalini|Sales|Banking|Kanpur|Active| 30|Sandeep Soni |Production|Govt|Delhi|Active|

report

answer="y" while [ "$answer" = "y" ] do echo "---Reports---" echo "1. New Employees" echo "2. Transfer Employees" echo "3. Employees who have quit" echo "Select an option" read option

case "$option" in 1) cat newemployees ;;   2) for i in `cut -d"|" -f1 location` do         #echo "i=$i" grep "^$i" masterfile done ;; 3) "3 selected" esac

echo "Do you want to generate more reports" read answer

case "$answer" in      [yY]*) answer="y" ;;       [nN]*) answer="n" esac

done

quitfile

04|Lalu Yadav | 18|Ankur Anderson |

oldlocation

Chennai

newlocation

Mumbai

newfile

18|Ankur Anderson |Trainee |Telecom |Kanpur|Active |100| 01|Gunpreet Singh Kohli    |C.E.O      |Banking     |Delhi    |Active  |104| 02|Harpreet Singh |Senior Manager | Banking |Delhi|Active |189| 03|Digvijay Singh Sengar   |Sales      |Govt        |Chennai  |Active  |494| 05|Baby Sharma             |Manager    |Banking     |Mumbai   |Acitve  |572| 06|Arpit Thakur            |Chairman   |Insurance   |Kanpur   |Active  |024| 07|Sonal Rajab             |Production |Insurance   |Delhi    |Active  |018| 08|Altaf Sharma            |Trainee    |Govt        |Mumbai   |Active  |057| 09|M.D Aziz                |Sales      |Insurance   |Mumbai   |Active  |632| 10|Shahrukh Khan |ASE |Banking |Delhi|Active |036| 11|Sanjay Mishra           |Manager    |Telecom     |Mumbai   |Active  |016| 12|Preeti Bedi             |Trainee    |Govt        |Kanpur   |Active  |342| 13|Pappu Khan              |Sales      |Telecom     |Chennai  |Active  |634| 14|Divya Soni              |Manager    |Bannking    |Delhi    |Active  |077| 15|Johny Singh             |Trainee    |Banking     |Kanpur   |Active  |003| 16|Silvia Sharma           |Production |Govt        |Kanpur   |Active  |026| 17|Mark Mohomad            |Production |Govt        |Delhi    |Active  |724| 18|Ankur Anderson |Trainee |Telecom |Kanpur|Active |100| 19|Devi Gilchrist          |Sales      |Banking     |Mumbai   |Active  |032| 20|Rajat John Singh        |Manager    |Telecom     |Chennai  |Acitve  |042| 01|Gunpreet Singh Kohli    |C.E.O      |Banking     |Delhi    |Active  |104| 02|Harpreet Singh |Senior Manager | Banking |Delhi|Active |189| 03|Digvijay Singh Sengar   |Sales      |Govt        |Chennai  |Active  |494| 04|Lalu Yadav |Sales |Insurance |Delhi|Active |318| 05|Baby Sharma             |Manager    |Banking     |Mumbai   |Acitve  |572| 06|Arpit Thakur            |Chairman   |Insurance   |Kanpur   |Active  |024| 07|Sonal Rajab             |Production |Insurance   |Delhi    |Active  |018| 08|Altaf Sharma            |Trainee    |Govt        |Mumbai   |Active  |057| 09|M.D Aziz                |Sales      |Insurance   |Mumbai   |Active  |632| 10|Shahrukh Khan |ASE |Banking |Delhi|Active |036| 11|Sanjay Mishra           |Manager    |Telecom     |Mumbai   |Active  |016| 12|Preeti Bedi             |Trainee    |Govt        |Kanpur   |Active  |342| 13|Pappu Khan              |Sales      |Telecom     |Chennai  |Active  |634| 14|Divya Soni              |Manager    |Bannking    |Delhi    |Active  |077| 15|Johny Singh             |Trainee    |Banking     |Kanpur   |Active  |003| 16|Silvia Sharma           |Production |Govt        |Kanpur   |Active  |026| 17|Mark Mohomad            |Production |Govt        |Delhi    |Active  |724| 19|Devi Gilchrist          |Sales      |Banking     |Mumbai   |Active  |032| 20|Rajat John Singh        |Manager    |Telecom     |Chennai  |Acitve  |042|

newEmployees

1|Chandra Mohan|Manager|Banking|Delhi|Active| 2|Dipanshu Wahi|Sales|Telecom|Mumbai|Active| 3|Gyanendra|Trainee|Govt|Kanpur|Active| 4|Suneeta|Production |Insurence|Chennai|Active| 5|Laxman Singh|Trainee|Banking|Kanpur|Active| 6|Laxmi Kant|manager|Telecom|Mumbai|Active| 7|Kuldeep Singh|Production|Govt|Chennai|Active| 8|Shyam|Sales|Insurence|Mumbai|Active| 9|Shalini|Sales|Banking|Kanpur|Active| 10|Sandeep Soni |Production|Govt|Delhi|Active|

mumbai

01|Gunpreet Kohli|Manager|BFs|Delhi|Active|

01|Gunpreet Kohli|Manager|BFs|Delhi|Active|

01|Gunpreet Kohli|Manager|BFs|Delhi|Active|

01|Gunpreet Kohli|Manager|BFs|Delhi|Active|

01|Gunpreet Kohli|Manager|BFs|Delhi|Active|

01|Gunpreet Kohli|Manager|BFs|Delhi|Active|

01|Gunpreet Kohli|Manager|BFs|Delhi|Active|

01|Gunpreet Kohli|Manager|BFs|Delhi|Active|

01|Gunpreet Kohli|Manager|BFs|Delhi|Active|

01|Gunpreet Kohli|Manager|BFs|Delhi|Active|

01|Gunpreet Kohli|Manager|BFs|Delhi|Active|

masters

echo "Welcome to the employee management system" answer="y" while [ "$answer" = "y" ] do echo "Menu" echo "1.Employee Database" echo "2."Add New Employees"  echo "3.Update Employee Status"   echo "4. Generate Report"  echo "Select an option"   read option   case "$option" in     1) cat masterfile ;;      #cp masterfile tempmasterfile     2)   sh addemployee.sh ;;     3) echo "Option 3 selected" ;;     4) echo "Reports--"       # echo -e "\n 1. New Employees"       # echo -e  "\n2. Transfered Employees"      # echo -e  "\n3. Quit Emplo esac done

masterfile

01|Gunpreet Singh Kohli|C.E.O|Banking|Delhi|Quit|104| 02|Harpreet Singh|Sr Manager |Banking|Delhi|Quit|189| 03|DigviJay Singh Sengar|Sales|Govt |Chennai|Quit|494| 04|Lalu Yadav |Sales |Insurance|Delhi|Quit|318| 05|Baby Sharma|Manager|Banking |Mumbai|Acitve|572| 06|Arpit Thakur|Chairman|Insurance|Kanpur|Quit|024| 07|Sonal Rajab|Production|Insurance|Delhi|Quit |018| 08|Altaf Sharma|Trainee|Govt|Mumbai|Quit|057| 09|M.D Aziz|Sales|Insurance|Mumbai|Quit|632| 10|Shahrukh Khan|ASE|Banking|Delhi|Quit|036| 11|Sanjay Mishra|Manager|Telecom|Mumbai|Quit |016| 12|Preeti Bedi|Trainee|Govt|Kanpur|Quit|342| 13|Pappu Khan|Sales|Telecom|Chennai|Quit|634| 14|Divya Soni|Manager|Bannking|Delhi|Quit|077| 15|Johny Singh|Trainee|Banking|Kanpur|Quit|003| 16|Silvia Sharma|Production|Govt|Kanpur|Quit|026| 17|Mark Mohomad|Production|Govt|Delhi |Quit|724| 18|Ankur Anderson|Trainee|Telecom|Kanpur|Quit|100| 19|Devi Gilchrist|Sales|Banking|Mumbai |Quit|032| 20|Rajat John Singh|Manager|Telecom |Chennai|Acitve|042|

master

echo "Welcome to the employee management system" answer="y" while [ "$answer" = "y" ] do echo "Menu" echo "1.Employee Database" echo "2."Add New Employees"  echo "3.Update Employee Status"   echo "4. Generate Report"  echo "Select an option"   read option   #case "$option" in    # 1) cat masterfile ;;      #cp masterfile tempmasterfile    # 2)   sh addemployee.sh ;;    # 3) echo "Option 3 selected" ;;     #4) echo "Reports"     # esac        $answer="n"  done

markquit

for i in `cut -d"|" -f 1 quitfile` do echo " value of $i"; val=`grep "^$i|" masterfile | wc -l` if test $val -eq 1 then grep "^$i|" masterfile >> unupdatedrows fi done sed -n 's/Active /Quit /p' unupdatedrows > newquitfile

for i in `cut -d"|" -f 1 newquitfile` do echo " value of $i"; val=`grep "^$i|" masterfile | wc -l` if test $val -eq 1 then grep -v "^$i|" masterfile > unupdatedrows grep "^$i|" newquitfile >> unupdatedrows sort -n unupdatedrows > masterfile fi done cat masterfile

locschange

for i in {1..7} do echo "i=$i" awk -F"|" -v tem=$i ' NR == tem { print }' location > tempfile cut -d"|" -f1 tempfile > sinlgeempid empid=`cat singleempid` id=`expr $empid + 0` lower='expr $id - 1` echo "Lowr half= $lower" cut -d"|" -f2 tempfile > oldlocation oldloc=`cat oldlocation` cut -d"|" -f3 tempfile > newlocation newloc=`cat newlocation` awk -F"|" -v x=$lower ' NR == 1, NR == x { print }' tempmasterfile > firsthalf cat firsthal done

locchange

for i in {1..7} do awk -F"|" -v var=$i ' NR == var { print }' location > tempfile cat tempfile cut -d"|" -f1 tempfile > singleid empid=`cat singleid` id=`expr $empid + 0` empid=$id lower=`expr $empid - 1` echo "Enp id=$empid" cut -d"|" -f2 tempfile > oldlocation old=`cat oldlocation` cut -d"|" -f3 tempfile > newlocation new=`cat newlocation`

awk -F"|" -v var=$lower ' NR == 1, NR == var { print }' tempmasterfile > firsthalf cat firsthalf echo "The middle record" grep "^$empid" tempmasterfile > middle cat middle awk -F"|" -v m="$new" '{ printf "%d|%s|%s|%s|%s|%s|",$1,$2,$3,$4,m,$6 }' middle done

Locationchange

for i in {1..7} do echo "i=$i" awk -F"|" -v x=$i ' NR == x { print }' location > singlerecord cat singlerecord cut -d"|" -f1 singlerecord > singleempid var=`cat singleempid` vars="$var" echo "var=$var" cut -d"|" -f2 singlerecord > oldlocation cat oldlocation oldloc=`cat oldlocation` echo "old location=$oldloc" cut -d"|" -f3 singlerecord > newlocation newloc=`cat newlocation` echo "new location=$newloc" sed "$vars s/$oldloc/$newloc/g" tempmasterfile > tempfile #grep "$var" tempmasterfile cat tempfile cat tempfile > tempmasterfile done

Location

01|Delhi|Mumbai 16|Kanour|Mumbai 25|Kanpur|Delhi 12|Kanpur|Chennai 27|Chennai|Mumbai 19|Mumbai|Delhi 20|Chennai|Mumbai

addemployee

employeeid=`wc -l < masterfile` var=$employeeid echo "emp id=$employeeid" for i in {1..10} do awk -F"|" -v x=$i ' NR == x { print } ' newemployees > stringfile empid=`expr $var + 1` var=$empid echo "New id = $var" awk -F"|" -v p=$var '{ printf "%d|%s|%s|%s|%s|%s|",p,$2,$3,$4,$5,$6 }' stringfile > tempfile cat tempfile >> tempmasterfile echo -e "\n" >> tempmasterfile done sed '/^[	]*$/d' tempmasterfile > tempfile cat tempfile > tempmasterfile cat tempmasterfile
 * 1) echo "i=$i"
 * 1) cat stringfile

ye lo...ji lo apni zindagi
create table employee(e_id NUMBER(3),ename VARCHAR(25),desi VARCHAR(15),proj_dept VARCHAR(20),status VARCHAR(15),location VARCHAR(15));

desc ; // to display the str of table

alter table employee add salary NUMERIC(7,2);

alter table employee modify location CHAR(3);

alter table employee drop column salary;

alter table employee rename column EID to emp_id, ENAME ename,DESIG desi;

alter table employee add constraint e_id primary key(e_id);

select constraint_name,constraint_type from user_constraints where table_name=EMPLOYEE

create table department (dno char(3),dname varchar(25),loc char(3));

alter table employee add constraint emp_fk foreign key(dno) references department(dno);

---24/5/2011--

alter table employee drop primary key; // to drop ne contraint like primary key,not null,unique etc

drop table

truncate table

rename to

--DML commands---

insert into department values('01','HR','DEL'); insert into department values('02','Finance','DEL'); insert into department values('03','Infrastructure','DEL'); insert into employee values(400,'harpreet singh','CEO','HR','ACTIVE','Delhi','01'); insert into employee (ename,desi,proj_dept,status,location,dno,e_id) values('gunpreet','Chairman','HR','ACTIVE','Delhi','01',403); insert into employee values(&id,'&name','&desig','&dept','&status','locatn','&dno');

update employee set location='Delhi' where ename='nandu';

delete from employee where ename='nandu';

--select statement select * from employee; select * from employee where e_id in (400,403); select * from employee where e_id between 400 and 403; select * from employee where ename like 'h%'; select * from employee where ename like '%preet%';

---FUNCTION---

select instr(ename) select upper(ename),upper(design) from emp; select lower(ename) from emp;

select round(125.3314,2) from dual; select round(25.25,-1) from dual; select round(25.25,-2) from dual; select trunc(125.3371,2) from dual;

select add_months('13-march-2011',3) from dual; select months_between('13-march-2011','13-May-2011') from dual; -->  -2 select months_between('13-march-2011','13-May-2010') from dual; --> 10 select next_day('24-may-2011','saturday') from dual;            --> 28-May-11 select last_day('24-feb-2011') from dual;  --> 28-feb-11

select to_char('01-2011-jan') from dual; select to_date('01-2011-jan') from dual;

select nvl(null,'expr2') from dual; --> expr2 select nvl('expr1','expr2') from dual; --> expr1

select nvl2('expr1','expr2','expr3') from dual; -->expr2

select nullif('expr1','expr1') from dual; --> null select nullif('expr1','expr2') from dual; --> expr1

select coalesce(null,null,null,'expr1','expr2','expr3'); --> expr1

---25/05/2011

create view emp_view as (select ename,design,sal,dno from emp);

create table duplicate_emp as (se-lect * from emp where 1=2); // creates just the str of table no data in it bcz of where clause

drop view emp_view;

select dno,count(emp_no) from emp group by dno; select max(sal) from emp group by dno; select max(sal) from emp group by dno having max(sal)>7000;

JOINS

create table emp1(eid number(2),ename varchar(20),mid number(2)); create table dept1(ename varchar(20),mname varchar(20));

insert into emp1 values(1,'x',3); insert into emp1 values(2,'y',3); insert into emp1 values(3,'z',1); insert into emp1 values(4,'a',1);

insert into dept1 values('x','z'); insert into dept1 values('y','z'); insert into dept1 values('z','x'); insert into dept1 values('a','x');

select e1.ename,e2.ename as mname from emp1 e1,emp1 e2 where e2.eid=e1.mid;

The professor says....
create or replace procedure upageexp as  age number; var empl%rowtype; cursor mycursor is select * from empl; begin dbms_output.put_line('Listing the employee id'); for curr_row in mycursor loop dbms_output.put_line('Eid='||curr_row.eid); age:=calage(curr_row.dob); dbms_output.put_line('Age>'||age); end loop; end; /


 * 1)   creating a function for calculating the employee age$$$$$$$$$$$$$$$$$$$$$$$$$

create or replace function calage(dob date) return number as    age number; begin select to_number(to_char(sysdate,'yyyy'))-to_number(to_char(to_date(dob),'yyyy')) into age from dual; return age; end; /

Function created.