Class 06 04-2014
Upcoming SlideShare
Loading in...5
×
 

Class 06 04-2014

on

  • 63 views

 

Statistics

Views

Total Views
63
Views on SlideShare
63
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Class 06 04-2014 Class 06 04-2014 Document Transcript

  • cut command :- $cat > fields mahesh : satish : narendra raja : naren : visu madan : sanna : chandu ctrl d $cut -d ":" -f2 fields satish naren sanna $cut -d ":" -f3 fields narendra visu chandu $cut -d ":" -f1 fields mahesh raja madan $cut -c1,5 fields $cut -c1-3 fields $cut -d " " -f2 test.txt ------------------------------ FIND - searching all files which we have been in the directory on time based -name file pattern -f file -d directory -type -mtime no.of days -mmin no.of minutes -print $find . -mtime -7 7 days before $find $HOME -mtime -7 -name "*.sh" $find . -mtime +1 $find . -mmin -30 -name "*.c" --------------------------------
  • vi editor :- - line editor - text editor - we can edit the text in vi editor $vi filename eg:- $vi abc i insert mode in this mode itself we can able to enter the text o open mode inserts an empty line at current cursor position r replace mode replaces the text with specified characters character by character replacement a append mode adding the text from current cursor position $vi abc united global soft offers the following oracle sql pl/sql oracle forms,reports oracle dba oracle apps dba esc :w - save :q - quit :wq - save and quit :q! - Quit without save x - removes a single character from current cursor position dW - removes a word from current cursor position dd - removes an entire line from current cursor position :1co 3 - first line is copying into 3 rd line :1,4co 6- first 4 lines copying to 6th line :2,5mo 6- from 2nd to 5th lines moving to 6th line :1,3d - removes first 3 lines
  • j - moving to down k - moving to up l - moving to right h - moving to left $vi sample echo "Welcome to UNIX SHELL " esc :wq $sh sample Welcome to UNIX SHELL operators in Shell :- + addition - substraction * multiplication / division % modulo division When we use arithmetic operators to write arithmetic expressions we should write `expr ` $vi arith.sh echo "Enter a value : " read a echo "Enter b value : " read b echo "Addition = " `expr $a + $b` echo "Substraction=" `expr $a - $b` echo "Multiplication=" `expr $a * $b` echo "Division = " `expr $a / $b` echo "Modulo Division =" `expr $a % $b` esc :wq $sh arith.sh Relational operators :- -lt less than -le less than or equal to -gt greater than -ge greater than or equal to
  • -eq equal to -ne not equal to Logical operators :- -a (AND) -o (OR) -n (NOT) T T T T F T T F T F F F T T F T F T F F F F F F F T T T Control Statements :- if - else if [ condition ] then .. .. else .. .. fi instead of writing [ ] to write condition, we can use test command if test condition then .. .. else .. . fi $vi even.sh echo "Enter a Number : " read n if [ `expr $n % 2` -eq 0 ] then echo "Even Number" else echo "Odd Number" fi esc :wq $sh even.sh $vi big.sh echo "Enter a number : " read a echo "Enter b number : " read b if test $a -gt $b then echo "a is big" else echo "b is big"
  • fi esc :wq $sh big.sh elif :- if [ condition ] then .. .. elif [ condition ] then .. .. elif [ condition ] then .. .. else .. .. fi $vi biggest.sh echo "Enter a,b,c,d values : " read a read b read c read d if [ $a -gt $b -a $a -gt $c -a $a -gt $d ] then echo $a " is big" elif [ $b -gt $c -a $b -gt $d ] then echo "b is big" elif [ $c -gt $d ] then echo "c is big" else echo "d is big" fi esc :wq $sh biggest.sh $vi report.sh echo "Enter 3 subject marks : " read m read p read c if test $m -ge 35 -a $p -ge 35 -a $c -ge 35 then echo "PASS" tot=`expr $m + $p + $c` avg=`expr $tot / 3` echo "Total Marks = " $tot echo "Average = " $avg
  • if test $avg -ge 75 then echo "Distinction" elif test $avg -ge 60 -a $avg -lt 75 then echo "First Class" elif test $avg -ge 50 -a $avg -lt 60 then echo "Second Class" elif test $avg -ge 35 -a $avg -lt 50 then echo "Third Class" fi else echo "Fail" fi esc :wq $sh report.sh Conditional looping statements :- while loop :- while [ condition ] do .. .. done in while loop, first control check the condition, if condition is true then only statements will be evaluated, after executing statements again control will go to condition, if condition is true then once again statements will be evaluated till given condition is false $vi number.sh i=1 while [ $i -le 10 ] do echo $i i=`expr $i + 1` done esc :wq $sh number.sh $vi numbers.sh i=1 while [ $i -le 10 ] do if [ `expr $i % 2` -eq 0 ] then echo $i fi i=`expr $i + 1` done
  • esc :wq $sh numbers.sh for loop :- for variablename in valuelist do ... .. done eg:- $vi loop.sh for i in 1 2 3 4 5 do echo $i done esc :wq $sh loop.sh $vi loop1.sh for i in 1 2 3 4 5 6 7 8 9 10 do if test `expr $i % 2` -eq 0 then echo $i fi done esc :wq $sh loop1.sh $vi loop2.sh for i=1..10 step 2 do echo $i done esc :wq $sh loop2.sh step 2 means increment by 2 1 3 5 7 9 Unconditional branching :-
  • case .. esac case value in 1) ..;; 2) ..;; 3) ..;; .. .. *) ..;; esac $vi uncond.sh echo "Enter a ,b values : " read a read b echo "1.Addition" echo "2.Substraction" echo "3.Multiplication" echo "4.Division" echo "5.Modulo Division" echo "Enter Your Choice [1/2/3/4] : " read ch case $ch in 1) echo "Addition = " `expr $a + $b`;; 2) echo "Substraction =" `expr $a - $b`;; 3) echo "Multiplication = " `expr $a * $b`;; 4) echo "Division = " `expr $a / $b`;; 5) echo "Modulo Division =" `expr $a % $b`;; *) echo "Invalid Option";; esac esc :wq $sh uncond.sh $vi uncond1.sh echo "1.Display content of courses file" echo "2.Display present working directory" echo "3.Display first 3 lines of courses file" echo "4.Listing all files and directories" echo "Enter Your Choice [1/2/3/4] : " read ch case $ch in 1) cat courses;; 2) pwd;; 3) head -3 courses;; 4) ls -l;; *) echo "Invalid Entry";; esac esc :wq $sh uncond1.sh