SlideShare a Scribd company logo
1 of 22
UNIT-III
Vi Editor,AWK Filters, Perl Manipulator
VI EDITOR
Vi editor is a visual screen editor which is available in almost all Unix systems. It is a
fast powerful editor.
Starting vi-
 to Start vi editor just type vi followed by the filename. Is the file is already exists
then it will show the contents of the file and allow you to edit them and if the file
dosent exist then it will create a new file.
 $ vi filename
MODES OFVI
1. Command mode: in this mode only commands will work to arrange, copy or
delete the data.Vi always start out in command mode and if you are working
and then you want to switch it back in command mode press ESC.
2. Insert mode: in this mode data can be enter into the file. By pressing ‘I’ will shift
you into the insert ode from command mode.
General command information:
Vi commands are
 Case sensitive
 Are not displayed on the screen when we type them.
 Generally do not require return after we type the command.
MOVING ONE CHARACTER AT ATIME:
h Left one space
i Right one space
j Down one space
k Up one space
MOVING AMONG WORDS AND LINES:
w Moves the cursor forward one word
b Moves the cursor backward one word
e Moves to the end of a word
ctrl+f Scrolls down one screen
ctrl+b Scrolls up one screen
ctrl+u Scrolls up half a screen
ctrl+d Scrolls down half a screen
Shortcuts: Two shortcuts for moving quickly on a line include $ and 0.
$ - will move us to the end of a line.
0 - will move us to the beginning of a line.
Screen Movement:
x Deletes the character under the cursor
X Deletes the character to the left of the cursor
dw Deletes the character selected to the end of the word
dd Deletes all the current line. (7dd – will deletes 7 lines)
D Deletes from the current character to the end of the line.
Yw Copies a word into buffer (7yw will copy 7 words)
Yy Copies a line into buffer (7yy will copy 7 lines)
P Will paste all the copied things.
Deleting Characters, Words and Lines:
Copying and Pasting text:
u Undoes the last change we made anywhere in the file
U Undoes all the recent changes to current line.
J To join lines (4J - to join 4 lines)
:w To save your file but not quit vi
:q To quit if we have not made any edits
:wq To quit and save edits
ZZ To quit and save edits (same as above)
:!q Force quit ( when it is not allowing you to quit file do force quit)
Quitting and Saving a File
Joining and Undoing a line
/ [string] Search forward for string
? [string] Search backward for string
N Repeat last search
:1,10w file Write lines 1 through 10 to file newfile
:sh Escape temporarily to a shell
^d Return from shell to vi
:set number Show line numbers
:set all Display current values of vi
Searching and Substitution Commands
Other Commands:
PROGRAMMING WITH AWK
 Awk is not just a command but a programming language too. It uses unusual
syntax that uses two components and requires single quotes and curly braces.
awk options ‘selection criteria {action}’ files
 The selection criteria (a form of addressing) filters input and selects lines for the
action component to act on.This component is enclosed within curly braces.
 The address (rather than selection criteria) and action constitutes and awk
program that is surrounded by a set of single quotes.
awk –F: ‘$3>200’ { print $1, $3 }’ /etc/passwd
Selection
Criteria
Action
Use to split fields with white spaces or on the delimiter specified with –F option
SPLITTING A LINE INTO FIELDS
 AWK breaks-up a line into fields on whitespaces or on the de-limiter specified with
the –F option. These fields are represented by the variables $1, $2, $3 and so forth.
$0 represents the full line.
 Since these parameters are evaluated by the shell in double quotes, awk
programs must be a single quoted.
$awk –F”|” ‘/sales/ { print $2,$3,$4 } empn.lst
In the above line, awk will fetch all the records contains keyword ‘sales’ and will
print second, third and fourth word from empn.lst.
COMPARISON OPERATORS
 $awk –F”|” ‘$3 == “director” || $3==“chairman” empn.lst
- Prints the complete line.
 $awk –F”|” ‘$3 == “director” || $3==“chairman” { printf “%-20s %-12s %dn, $2,$3, $6 }”
empn.lst
-prints the specific words.
John woodcook director 120000 20939
Barry wood chairman 160000 27288
John woodcook director 120000
Barry wood chairman 160000
Bill Johnson Director 130000
…
 $awk –F”|” ‘$3 == “director” || $3==“chairman” { printf “NR, %-20s %-12s %dn,
$2,$3, $6 }” empn.lst
-NR is a new keyword which prints the line number.
 $awk –F”|” ‘$6 > 120000 { printf “NR, %-20s %-12s %dn, $2,$3, $6 }” empn.lst
13 John woodcook director 120000
15 Barry wood chairman 160000
19 Bill Johnson Director 130000
COMPARISON OPERATORS
< LessThan
<= Less than or equal to
== Equal to
!= Not Equal to
>= Greater than or equal to
> Greater than
~ Matches a regular expression
!~ Does not match a regular expression
NUMBER PROCESSING
 Awk can perform computations on numbers using the arithmetic operators +, -,
*, / and % (modulus).
 Salespeople often earn a bonus apart from salary. We will assume here that the
bonus amount is equal one month’s salary.
$awk –F”|” ‘$4 == “sales” { printf “NR, %-20s %-12s %6d %8.2fn,
NR,$2,$3,$6,$6/12 }” empn.lst
13 John woodcook director 90000 7500.00
15 Barry wood chairman 140000 11666.67
19 Bill Johnson Director 110000 9166.67
VARIABLES
 AWK has certain built-in variables like,
 NR
 $0
 AWK provides user a flexibility to define own variables. It has two special feature-
 No type declarations are needed.
 By default and depending on its type, variables are initialized to zero or a null string.
AWK has a mechanism of identifying the typeof a variable used from its context.
$awk –F”|” ‘$4 == “sales” {
>kount = kount + 1
>printf “NR, %-20s %-12s %6d %8.2fn,kount,NR,$2,$3,$6,$6/12 }” empn.lst
1 13 John woodcook director 90000 7500.00
2 15 Barry wood chairman 140000 11666.67
BUILT-INVARIABLES
NR Cumulative number of lines read
FS Input field separator
OFS Output field separator
NF Number of fields in the current line
FILENAME Current input file
ARGC Number of arguments in command line
ARGV List of arguments
THE BEGIN AND END SECTIONS
 If you have to print something before you process the input, the BEGIN section
can be used quite gainfully. Similarly, the end section is equally useful for printing
some totals after the processing is over.
 BEGIN { action }
 END { action }
LET’S DO A PROGRAM
 $cat emawk2.awk
BEGIN { printf “ntt Employee Detailsnn”
}
$6 > 12000 { #Increment variables for serial number and pay
kount++; total+-$6
printf “%3d %-20s %-12s %sn”, kount,$2,$3,$6
}
END { printf “ntThe average salary is %6dn”, total/kount
}
EXECUTION & OUTPUT
 $ awk –F”|” –f empawk2.awk empn.lst
Employee Details
The average salary is 115000
1 John woodcook director 90000
2 Barry wood chairman 140000
ARRAYS
 Awk handles only one-dimensional arrays.
 No array declaration is required.
 It is automatically initialized to zero unless initialized explicitly.
$ cat empawk4.awk
BEGIN { FS = “|” ; printf “%40sn”, “Salary Commission” }
/sales/ {
commission = $6*0.20
tot[1]+=$6; tot[2]+=commission
kount++;
}
END { printf “T Average %5d %5dn”, tot[1]/kount, tot[2]/kount
}
OUTPUT
$ awk –f empawk4.awk empn.lst
Salary Commission
Average 105625 21125
FUNCTIONS
 AWK has several built-in functions performing both arithmetic and string
operations.
$ awk –F”|” ‘length($2) < 11’ empn.lst
It will search those people who have short names.
int(x) Returns integer value of x
sqrt(x) Returns the square root of x
length Returns length of complete line
length($x) Returns length of x
substr(stg,m,n) Returns portion of string length n, starting from position m in a string stg
index(s1,s2) Returns position of string s2 in string s1
split(stg,arr,ch) Split string stg into array arr using ch as delimiter; optionally returns number of fields
system(“cmd”) Runs UNIX command cmd, and returns its exit status
THANKS

More Related Content

What's hot

Php Chapter 1 Training
Php Chapter 1 TrainingPhp Chapter 1 Training
Php Chapter 1 TrainingChris Chubb
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’eShikshak
 
C Programming Language Step by Step Part 5
C Programming Language Step by Step Part 5C Programming Language Step by Step Part 5
C Programming Language Step by Step Part 5Rumman Ansari
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8Rumman Ansari
 
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)Tomohiro Kumagai
 
Abap 7 02 new features - new string functions
Abap 7 02   new features - new string functionsAbap 7 02   new features - new string functions
Abap 7 02 new features - new string functionsCadaxo GmbH
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and stringsRai University
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsRai University
 
Decent exposure: Controladores sin @ivars
Decent exposure: Controladores sin @ivarsDecent exposure: Controladores sin @ivars
Decent exposure: Controladores sin @ivarsLeonardo Soto
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsRai University
 
Open SQL & Internal Table
Open SQL & Internal TableOpen SQL & Internal Table
Open SQL & Internal Tablesapdocs. info
 

What's hot (20)

Aggregate function
Aggregate functionAggregate function
Aggregate function
 
Les18
Les18Les18
Les18
 
Php Chapter 1 Training
Php Chapter 1 TrainingPhp Chapter 1 Training
Php Chapter 1 Training
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Les04
Les04Les04
Les04
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
C Programming Language Step by Step Part 5
C Programming Language Step by Step Part 5C Programming Language Step by Step Part 5
C Programming Language Step by Step Part 5
 
Single row functions
Single row functionsSingle row functions
Single row functions
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
 
Lab4 join - all types listed
Lab4   join - all types listedLab4   join - all types listed
Lab4 join - all types listed
 
Abap 7 02 new features - new string functions
Abap 7 02   new features - new string functionsAbap 7 02   new features - new string functions
Abap 7 02 new features - new string functions
 
Les03
Les03Les03
Les03
 
F# intro
F# introF# intro
F# intro
 
Les04
Les04Les04
Les04
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
 
Decent exposure: Controladores sin @ivars
Decent exposure: Controladores sin @ivarsDecent exposure: Controladores sin @ivars
Decent exposure: Controladores sin @ivars
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
 
Open SQL & Internal Table
Open SQL & Internal TableOpen SQL & Internal Table
Open SQL & Internal Table
 

Similar to VI Editor (20)

Awk-An Advanced Filter
Awk-An Advanced FilterAwk-An Advanced Filter
Awk-An Advanced Filter
 
Beginning with vi text editor
Beginning with vi text editorBeginning with vi text editor
Beginning with vi text editor
 
Logo tutorial
Logo tutorialLogo tutorial
Logo tutorial
 
DataWeave 2.0 - MuleSoft CONNECT 2019
DataWeave 2.0 - MuleSoft CONNECT 2019DataWeave 2.0 - MuleSoft CONNECT 2019
DataWeave 2.0 - MuleSoft CONNECT 2019
 
Mission vim possible
Mission vim possibleMission vim possible
Mission vim possible
 
Vi editor
Vi editorVi editor
Vi editor
 
Using Vi Editor.pptx
Using Vi Editor.pptxUsing Vi Editor.pptx
Using Vi Editor.pptx
 
Using Vi Editor.pptx
Using Vi Editor.pptxUsing Vi Editor.pptx
Using Vi Editor.pptx
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
 
Hechsp 001 Chapter 2
Hechsp 001 Chapter 2Hechsp 001 Chapter 2
Hechsp 001 Chapter 2
 
Prog1 chap1 and chap 2
Prog1 chap1 and chap 2Prog1 chap1 and chap 2
Prog1 chap1 and chap 2
 
Vi editor
Vi editorVi editor
Vi editor
 
Call Execute For Everyone
Call Execute For EveryoneCall Execute For Everyone
Call Execute For Everyone
 
Linux class 15 26 oct 2021
Linux class 15   26 oct 2021Linux class 15   26 oct 2021
Linux class 15 26 oct 2021
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
Presentation 2
Presentation 2Presentation 2
Presentation 2
 
Awk hints
Awk hintsAwk hints
Awk hints
 
Awk programming
Awk programming Awk programming
Awk programming
 
The Ring programming language version 1.9 book - Part 25 of 210
The Ring programming language version 1.9 book - Part 25 of 210The Ring programming language version 1.9 book - Part 25 of 210
The Ring programming language version 1.9 book - Part 25 of 210
 
Excel tutorial
Excel tutorialExcel tutorial
Excel tutorial
 

More from Nishant Munjal

Database Management System
Database Management SystemDatabase Management System
Database Management SystemNishant Munjal
 
Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointerNishant Munjal
 
Introduction to computers
Introduction to computersIntroduction to computers
Introduction to computersNishant Munjal
 
Shell Programming Concept
Shell Programming ConceptShell Programming Concept
Shell Programming ConceptNishant Munjal
 
Asynchronous Transfer Mode
Asynchronous Transfer ModeAsynchronous Transfer Mode
Asynchronous Transfer ModeNishant Munjal
 
Overview of Cloud Computing
Overview of Cloud ComputingOverview of Cloud Computing
Overview of Cloud ComputingNishant Munjal
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries InformationNishant Munjal
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization TechniquesNishant Munjal
 
Transaction Processing Concept
Transaction Processing ConceptTransaction Processing Concept
Transaction Processing ConceptNishant Munjal
 
Database Management System
Database Management SystemDatabase Management System
Database Management SystemNishant Munjal
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model IntroductionNishant Munjal
 
Virtualization, A Concept Implementation of Cloud
Virtualization, A Concept Implementation of CloudVirtualization, A Concept Implementation of Cloud
Virtualization, A Concept Implementation of CloudNishant Munjal
 
Technical education benchmarks
Technical education benchmarksTechnical education benchmarks
Technical education benchmarksNishant Munjal
 

More from Nishant Munjal (20)

Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Functions & Recursion
Functions & RecursionFunctions & Recursion
Functions & Recursion
 
Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointer
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Introduction to computers
Introduction to computersIntroduction to computers
Introduction to computers
 
Unix Administration
Unix AdministrationUnix Administration
Unix Administration
 
Shell Programming Concept
Shell Programming ConceptShell Programming Concept
Shell Programming Concept
 
Introduction to Unix
Introduction to UnixIntroduction to Unix
Introduction to Unix
 
Routing Techniques
Routing TechniquesRouting Techniques
Routing Techniques
 
Asynchronous Transfer Mode
Asynchronous Transfer ModeAsynchronous Transfer Mode
Asynchronous Transfer Mode
 
Overview of Cloud Computing
Overview of Cloud ComputingOverview of Cloud Computing
Overview of Cloud Computing
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization Techniques
 
Concurrency Control
Concurrency ControlConcurrency Control
Concurrency Control
 
Transaction Processing Concept
Transaction Processing ConceptTransaction Processing Concept
Transaction Processing Concept
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
Virtualization, A Concept Implementation of Cloud
Virtualization, A Concept Implementation of CloudVirtualization, A Concept Implementation of Cloud
Virtualization, A Concept Implementation of Cloud
 
Technical education benchmarks
Technical education benchmarksTechnical education benchmarks
Technical education benchmarks
 
Bluemix Introduction
Bluemix IntroductionBluemix Introduction
Bluemix Introduction
 

Recently uploaded

Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 

Recently uploaded (20)

Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 

VI Editor

  • 2. VI EDITOR Vi editor is a visual screen editor which is available in almost all Unix systems. It is a fast powerful editor. Starting vi-  to Start vi editor just type vi followed by the filename. Is the file is already exists then it will show the contents of the file and allow you to edit them and if the file dosent exist then it will create a new file.  $ vi filename
  • 3. MODES OFVI 1. Command mode: in this mode only commands will work to arrange, copy or delete the data.Vi always start out in command mode and if you are working and then you want to switch it back in command mode press ESC. 2. Insert mode: in this mode data can be enter into the file. By pressing ‘I’ will shift you into the insert ode from command mode. General command information: Vi commands are  Case sensitive  Are not displayed on the screen when we type them.  Generally do not require return after we type the command.
  • 4. MOVING ONE CHARACTER AT ATIME: h Left one space i Right one space j Down one space k Up one space
  • 5. MOVING AMONG WORDS AND LINES: w Moves the cursor forward one word b Moves the cursor backward one word e Moves to the end of a word ctrl+f Scrolls down one screen ctrl+b Scrolls up one screen ctrl+u Scrolls up half a screen ctrl+d Scrolls down half a screen Shortcuts: Two shortcuts for moving quickly on a line include $ and 0. $ - will move us to the end of a line. 0 - will move us to the beginning of a line. Screen Movement:
  • 6. x Deletes the character under the cursor X Deletes the character to the left of the cursor dw Deletes the character selected to the end of the word dd Deletes all the current line. (7dd – will deletes 7 lines) D Deletes from the current character to the end of the line. Yw Copies a word into buffer (7yw will copy 7 words) Yy Copies a line into buffer (7yy will copy 7 lines) P Will paste all the copied things. Deleting Characters, Words and Lines: Copying and Pasting text:
  • 7. u Undoes the last change we made anywhere in the file U Undoes all the recent changes to current line. J To join lines (4J - to join 4 lines) :w To save your file but not quit vi :q To quit if we have not made any edits :wq To quit and save edits ZZ To quit and save edits (same as above) :!q Force quit ( when it is not allowing you to quit file do force quit) Quitting and Saving a File Joining and Undoing a line
  • 8. / [string] Search forward for string ? [string] Search backward for string N Repeat last search :1,10w file Write lines 1 through 10 to file newfile :sh Escape temporarily to a shell ^d Return from shell to vi :set number Show line numbers :set all Display current values of vi Searching and Substitution Commands Other Commands:
  • 9. PROGRAMMING WITH AWK  Awk is not just a command but a programming language too. It uses unusual syntax that uses two components and requires single quotes and curly braces. awk options ‘selection criteria {action}’ files  The selection criteria (a form of addressing) filters input and selects lines for the action component to act on.This component is enclosed within curly braces.  The address (rather than selection criteria) and action constitutes and awk program that is surrounded by a set of single quotes. awk –F: ‘$3>200’ { print $1, $3 }’ /etc/passwd Selection Criteria Action Use to split fields with white spaces or on the delimiter specified with –F option
  • 10. SPLITTING A LINE INTO FIELDS  AWK breaks-up a line into fields on whitespaces or on the de-limiter specified with the –F option. These fields are represented by the variables $1, $2, $3 and so forth. $0 represents the full line.  Since these parameters are evaluated by the shell in double quotes, awk programs must be a single quoted. $awk –F”|” ‘/sales/ { print $2,$3,$4 } empn.lst In the above line, awk will fetch all the records contains keyword ‘sales’ and will print second, third and fourth word from empn.lst.
  • 11. COMPARISON OPERATORS  $awk –F”|” ‘$3 == “director” || $3==“chairman” empn.lst - Prints the complete line.  $awk –F”|” ‘$3 == “director” || $3==“chairman” { printf “%-20s %-12s %dn, $2,$3, $6 }” empn.lst -prints the specific words. John woodcook director 120000 20939 Barry wood chairman 160000 27288 John woodcook director 120000 Barry wood chairman 160000 Bill Johnson Director 130000
  • 12. …  $awk –F”|” ‘$3 == “director” || $3==“chairman” { printf “NR, %-20s %-12s %dn, $2,$3, $6 }” empn.lst -NR is a new keyword which prints the line number.  $awk –F”|” ‘$6 > 120000 { printf “NR, %-20s %-12s %dn, $2,$3, $6 }” empn.lst 13 John woodcook director 120000 15 Barry wood chairman 160000 19 Bill Johnson Director 130000
  • 13. COMPARISON OPERATORS < LessThan <= Less than or equal to == Equal to != Not Equal to >= Greater than or equal to > Greater than ~ Matches a regular expression !~ Does not match a regular expression
  • 14. NUMBER PROCESSING  Awk can perform computations on numbers using the arithmetic operators +, -, *, / and % (modulus).  Salespeople often earn a bonus apart from salary. We will assume here that the bonus amount is equal one month’s salary. $awk –F”|” ‘$4 == “sales” { printf “NR, %-20s %-12s %6d %8.2fn, NR,$2,$3,$6,$6/12 }” empn.lst 13 John woodcook director 90000 7500.00 15 Barry wood chairman 140000 11666.67 19 Bill Johnson Director 110000 9166.67
  • 15. VARIABLES  AWK has certain built-in variables like,  NR  $0  AWK provides user a flexibility to define own variables. It has two special feature-  No type declarations are needed.  By default and depending on its type, variables are initialized to zero or a null string. AWK has a mechanism of identifying the typeof a variable used from its context. $awk –F”|” ‘$4 == “sales” { >kount = kount + 1 >printf “NR, %-20s %-12s %6d %8.2fn,kount,NR,$2,$3,$6,$6/12 }” empn.lst 1 13 John woodcook director 90000 7500.00 2 15 Barry wood chairman 140000 11666.67
  • 16. BUILT-INVARIABLES NR Cumulative number of lines read FS Input field separator OFS Output field separator NF Number of fields in the current line FILENAME Current input file ARGC Number of arguments in command line ARGV List of arguments
  • 17. THE BEGIN AND END SECTIONS  If you have to print something before you process the input, the BEGIN section can be used quite gainfully. Similarly, the end section is equally useful for printing some totals after the processing is over.  BEGIN { action }  END { action }
  • 18. LET’S DO A PROGRAM  $cat emawk2.awk BEGIN { printf “ntt Employee Detailsnn” } $6 > 12000 { #Increment variables for serial number and pay kount++; total+-$6 printf “%3d %-20s %-12s %sn”, kount,$2,$3,$6 } END { printf “ntThe average salary is %6dn”, total/kount }
  • 19. EXECUTION & OUTPUT  $ awk –F”|” –f empawk2.awk empn.lst Employee Details The average salary is 115000 1 John woodcook director 90000 2 Barry wood chairman 140000
  • 20. ARRAYS  Awk handles only one-dimensional arrays.  No array declaration is required.  It is automatically initialized to zero unless initialized explicitly. $ cat empawk4.awk BEGIN { FS = “|” ; printf “%40sn”, “Salary Commission” } /sales/ { commission = $6*0.20 tot[1]+=$6; tot[2]+=commission kount++; } END { printf “T Average %5d %5dn”, tot[1]/kount, tot[2]/kount } OUTPUT $ awk –f empawk4.awk empn.lst Salary Commission Average 105625 21125
  • 21. FUNCTIONS  AWK has several built-in functions performing both arithmetic and string operations. $ awk –F”|” ‘length($2) < 11’ empn.lst It will search those people who have short names. int(x) Returns integer value of x sqrt(x) Returns the square root of x length Returns length of complete line length($x) Returns length of x substr(stg,m,n) Returns portion of string length n, starting from position m in a string stg index(s1,s2) Returns position of string s2 in string s1 split(stg,arr,ch) Split string stg into array arr using ch as delimiter; optionally returns number of fields system(“cmd”) Runs UNIX command cmd, and returns its exit status