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

Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 

Recently uploaded (20)

Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 

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