SED with utilities

advertisement
e-Infochips Institute of Training Research and Academics Limited
Click to add Title
SED & it’s Utilities
By :- Priyambada Mishra
Prachi Trivedi
Milin Parekh
Karishma Babani
1
I N D E X
●
●
●
●
●
●
●
●
●
●
Comparison
Overview
Syntax (workflow)
SED Architecture
Loops and branches using SED
Another Basic Commands
Examples
Assignment Questions
REGEX
Strings and Special characters
2
COMPARISON
3
OVERVIEW
What is SED?
● A non-interactive Stream editor.
● A tool usually designed for a short line substitution,
deletion and print.
● SED reads the data one line at a time, make a copy
of the input line & places it in a buffer called the
pattern space.
● Modifies that copy in the pattern space.
● Outputs the copy to standard output.
IS THERE ANY CHANGE IN THE ORIGINAL FILE?
4
S Y N T A X
5
SED
ARCHITECTURE
6
PATTERN SPACE & HOLD SPACE
7
BRANCHING
PS: N is used to read next input lline
8
SOME BASIC COMMANDS AND EXAMPLES
COMMANDS
FILE
COMMANDS
QUIT
BRANCH
TRANSFORM
MODIFY
LINE NUMBER
HOLD SPACE
9
FILE
COMMANDS
WRITE (w)
READ (r)
EXECUTE (e)
10
11
Q U I T C O M M A N D (Q)
● instructs the SED to quit the current execution flow
● when the address is encountered, it simply stops the current execution.
SYNTAX
[address]q
EXAMPLE
12
T R A N S F O R M C O M M A N D (Y)
● transforms the characters by position
● regular expressions and character classes are unsupported
● cannot indicate a range of characters
SYNTAX
[address1[,address2]]y/list-1/list-2/
● both lists must be explicit character lists
● the size of list 1 and list 2 must be same.
EXAMPLE
13
MODIFY
APPEND
INSERT
DELETE
CHANGE
SUBSTITUTE
14
A P P E N D C O M M A N D (a)
● adds one or more lines directly to the output
● it cannot be used with a range address
SYNTAX
[address]a\
Append text
EXAMPLE
15
C H A N G E C O M M A N D (c)
● replace an existing line with new text
● accepts four address types:
single-line, set-of-line, range, and nested addresses
SYNTAX
[address1[,address2]]c\
Replace text
EXAMPLE
16
D E L E T E C O M M A N D (d)
● removes lines only from the pattern buffer
● original file remains unchanged
SYNTAX
[address1[,address2]]d
EXAMPLE
17
D A T A S E T
●
●
●
●
Hello i am Milin parekh
i am the bla bla bla
i have the habbit of bla bal bla
i have graduated from the VVP
engineering college
● i have fond of bal bla bla
1p
2p
3p
4p
.
$p
18
s - substitute
p- print / duplicate
d - delete
g - global
sed -n ‘/run/!p’ bite.txt
sed -n ‘/^$/p;p’ fight.txt
sed -n ‘/Atul/p’ salary.txt
19
REGEX
● It is the regular expressions that make SED powerful and
efficient. A number of complex tasks can be solved with
regular expressions.
Start of Line (^)
sed -n -e '/^3/ p' books.txt
End of line ($)
sed -n -e '/Coelho$/ p' books.txt
20
SIngle Character(.)
Zero on One
Occurrence (\?)
Escaping
Characters(\)
$ echo -e "cat\nbat\nrat\nmat\nbatting\nrats\" | sed -n '/^..t$/p'
$ echo -e "Behaviour\nBehavior" | sed -n '/Behaviou\?r/ p'
Pipe(|)
Exclusive Set
([^])
Zero or More
Occurrence
(*)
Match
Character Set
([])
21
STRINGS
22
STRING
S U B S T I TU T I O N
23
SUBSTITUTION OF
CHARACTER
24
SPECIAL
CHARACTER
25
REFERENCES
www.tutorialspoint.com/sed/
www.geeksforgeeks.com
26
27
Download