SlideShare a Scribd company logo
Chapter 6Chapter 6
Regular ExpressionRegular Expression
Ref. Pge. 32
Regular ExpressionRegular Expression
●
Processing in line baseProcessing in line base
●
Meta characters may conflict with shell,Meta characters may conflict with shell,
must be quotedmust be quoted
●
Commonly used in text filtering:Commonly used in text filtering:
– grep, sed, awk, perl, php, etc...grep, sed, awk, perl, php, etc...
Character setCharacter set
●
The way to treat character:The way to treat character:
abcabc :: individual characterindividual character
(abc)(abc) :: a set of charactera set of character
(abc|xyz)(abc|xyz) :: one set ofone set of
[abc][abc] :: one character of listone character of list
[^abc][^abc] :: one character of non-listone character of non-list
Anchor CharactersAnchor Characters
●
The position in a line:The position in a line:
^^ : the beginning of line: the beginning of line
$$ : the end of line: the end of line
<< : the beginning of word: the beginning of word
>> :: the end of wordthe end of word
ModifierModifier
●
To modify existence of the precedingTo modify existence of the preceding
character or set:character or set:
** :: zero or more timeszero or more times
?? :: zero or one timeszero or one times
++ :: one or more timesone or more times
{n}{n} :: nn timestimes
{n,m}{n,m} :: nn toto mm timestimes
BoundaryBoundary
●
Anything outside the boundary is ignoredAnything outside the boundary is ignored
●
Which of following matchWhich of following match abc{3,5}abc{3,5}??
aabccbcc
abccccabcccc
abccccccabcccccc
ANSWERANSWER
●
TheThe abc{3,5}abc{3,5} doesn't care about whatdoesn't care about what
character following thecharacter following the 5th5th c :c :
abcccccabccccccc
RE VersionRE Version
●
Extended and traditional:Extended and traditional:
ExtendedExtended TraditionalTraditional
++ ++
?? ??
()() ()()
{}{} {}{}
|| (none)(none)
UsingUsing grepgrep
●
grep 'RE' text.filegrep 'RE' text.file
– Display all lines matching REDisplay all lines matching RE
– Common optionsCommon options
●
­E­E : use extended version of RE: use extended version of RE
●
­i­i : ignore case: ignore case
●
­v­v : revers behavior: revers behavior
●
­n­n : show line number: show line number
●
­c­c : show matching counter: show matching counter
●
­l­l : show file name only: show file name only
●
­r­r : recursively search directory: recursively search directory
●
­q­q : silent mode: silent mode
Ref. Pge. 33
UsingUsing sedsed
●
sed <cmd> text.filesed <cmd> text.file
cmd=[address]cmdcmd=[address]cmd
– AddressAddress
●
<none><none> : all lines: all lines
●
nn,,mm : lines from: lines from nn toto mm ($ represents the last line)($ represents the last line)
●
/RE//RE/ : lines match RE: lines match RE
●
/RE1/,/RE2//RE1/,/RE2/ : lines from matching RE1 to RE2: lines from matching RE1 to RE2
Ref. Pge. 35
UsingUsing sedsed
●
CommonCommon sedsed commands:commands:
ii : insert a line above: insert a line above
aa : append a line bellow: append a line bellow
cc : change the match lines: change the match lines
dd : delete the match lines: delete the match lines
UsingUsing sedsed
●
TheThe ss command:command:
– s/RE/string/[flag]s/RE/string/[flag]
●
Substitute the first RE in a line to stringSubstitute the first RE in a line to string
●
Flags:Flags:
– nn : substitute the: substitute the nnth RE onlyth RE only
– gg : substitute the all REs: substitute the all REs
– ii : ignore case: ignore case
– s/RE/&string/s/RE/&string/
●
keep RE at position &keep RE at position &
– ss//(RE1)...(RE2)(RE1)...(RE2)//1string21string2//
●
keep RE1 at position 1 and RE2 at position 2, and sokeep RE1 at position 1 and RE2 at position 2, and so
on...on...
UsingUsing awkawk
●
awk 'program' text.fileawk 'program' text.file
– Common options:Common options:
●
­F s­F s : specify field separators (one or more): specify field separators (one or more)
●
­v var=value­v var=value : set variable: set variable
●
­f file­f file : read program from file: read program from file
UsingUsing awkawk
●
Program structure:Program structure:
expression {action}expression {action}
– Expression:Expression:
●
/RE//RE/
●
if ( ) statementif ( ) statement
●
while ( ) statementwhile ( ) statement
●
for ( ) statementfor ( ) statement
UsingUsing awkawk
– Common actions:Common actions:
●
print $<POS>print $<POS> : print position (whole line: 0): print position (whole line: 0)
●
printf <format>printf <format> : print in specified format: print in specified format
●
<arithmetic functions><arithmetic functions> : do calculation: do calculation
●
<string functions><string functions> : process string: process string
●
Many more...Many more...

More Related Content

What's hot

Clojure+ClojureScript Webapps
Clojure+ClojureScript WebappsClojure+ClojureScript Webapps
Clojure+ClojureScript Webapps
Falko Riemenschneider
 
Practical Example of grep command in unix
Practical Example of grep command in unixPractical Example of grep command in unix
Practical Example of grep command in unix
Javin Paul
 
Introduction to segmentation fault handling
Introduction to segmentation fault handling Introduction to segmentation fault handling
Introduction to segmentation fault handling
Larion
 
C: A Humbling Language
C: A Humbling LanguageC: A Humbling Language
C: A Humbling Language
guestaa63aa
 
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury SechetDConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
Andrei Alexandrescu
 
Make A Shoot ‘Em Up Game with Amethyst Framework
Make A Shoot ‘Em Up Game with Amethyst FrameworkMake A Shoot ‘Em Up Game with Amethyst Framework
Make A Shoot ‘Em Up Game with Amethyst Framework
Yodalee
 
Ruby : Block, Proc and, lambda
Ruby : Block, Proc and, lambdaRuby : Block, Proc and, lambda
Ruby : Block, Proc and, lambda
MatthieuSegret
 
Linux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell scriptLinux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell script
Kenny (netman)
 
Gameboy emulator in rust and web assembly
Gameboy emulator in rust and web assemblyGameboy emulator in rust and web assembly
Gameboy emulator in rust and web assembly
Yodalee
 
Protostar VM - Heap3
Protostar VM - Heap3Protostar VM - Heap3
Protostar VM - Heap3
UTD Computer Security Group
 
Code GPU with CUDA - Memory Subsystem
Code GPU with CUDA - Memory SubsystemCode GPU with CUDA - Memory Subsystem
Code GPU with CUDA - Memory Subsystem
Marina Kolpakova
 
Debugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB TricksDebugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB Tricksdutor
 
GoLightly: A Go Library For Building Virtual Machines
GoLightly: A Go Library For Building Virtual MachinesGoLightly: A Go Library For Building Virtual Machines
GoLightly: A Go Library For Building Virtual Machines
Eleanor McHugh
 

What's hot (14)

Clojure+ClojureScript Webapps
Clojure+ClojureScript WebappsClojure+ClojureScript Webapps
Clojure+ClojureScript Webapps
 
lec4.docx
lec4.docxlec4.docx
lec4.docx
 
Practical Example of grep command in unix
Practical Example of grep command in unixPractical Example of grep command in unix
Practical Example of grep command in unix
 
Introduction to segmentation fault handling
Introduction to segmentation fault handling Introduction to segmentation fault handling
Introduction to segmentation fault handling
 
C: A Humbling Language
C: A Humbling LanguageC: A Humbling Language
C: A Humbling Language
 
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury SechetDConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
 
Make A Shoot ‘Em Up Game with Amethyst Framework
Make A Shoot ‘Em Up Game with Amethyst FrameworkMake A Shoot ‘Em Up Game with Amethyst Framework
Make A Shoot ‘Em Up Game with Amethyst Framework
 
Ruby : Block, Proc and, lambda
Ruby : Block, Proc and, lambdaRuby : Block, Proc and, lambda
Ruby : Block, Proc and, lambda
 
Linux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell scriptLinux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell script
 
Gameboy emulator in rust and web assembly
Gameboy emulator in rust and web assemblyGameboy emulator in rust and web assembly
Gameboy emulator in rust and web assembly
 
Protostar VM - Heap3
Protostar VM - Heap3Protostar VM - Heap3
Protostar VM - Heap3
 
Code GPU with CUDA - Memory Subsystem
Code GPU with CUDA - Memory SubsystemCode GPU with CUDA - Memory Subsystem
Code GPU with CUDA - Memory Subsystem
 
Debugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB TricksDebugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB Tricks
 
GoLightly: A Go Library For Building Virtual Machines
GoLightly: A Go Library For Building Virtual MachinesGoLightly: A Go Library For Building Virtual Machines
GoLightly: A Go Library For Building Virtual Machines
 

Viewers also liked

101 3.7 search text files using regular expressions
101 3.7 search text files using regular expressions101 3.7 search text files using regular expressions
101 3.7 search text files using regular expressionsAcácio Oliveira
 
101 3.7 search text files using regular expressions
101 3.7 search text files using regular expressions101 3.7 search text files using regular expressions
101 3.7 search text files using regular expressions
Acácio Oliveira
 
3, regular expression
3, regular expression3, regular expression
3, regular expression
ted-xu
 
Presentation at RegX on Business Model Innovation and Speed Creation 20120904
Presentation at RegX on Business Model Innovation and Speed Creation 20120904Presentation at RegX on Business Model Innovation and Speed Creation 20120904
Presentation at RegX on Business Model Innovation and Speed Creation 20120904
Matthias Pohle
 
Windows7 Vs Linux
Windows7 Vs LinuxWindows7 Vs Linux
Windows7 Vs Linux
Yogesh Gandhi
 
Linux fundamental - Chap 08 proc
Linux fundamental - Chap 08 procLinux fundamental - Chap 08 proc
Linux fundamental - Chap 08 proc
Kenny (netman)
 
Linux CLI
Linux CLILinux CLI
Linux fundamental - Chap 10 fs
Linux fundamental - Chap 10 fsLinux fundamental - Chap 10 fs
Linux fundamental - Chap 10 fs
Kenny (netman)
 
The linux command line for total beginners
The linux command line  for total beginnersThe linux command line  for total beginners
The linux command line for total beginners
Corrie Watt
 
Linux fundamental - Chap 01 io
Linux fundamental - Chap 01 ioLinux fundamental - Chap 01 io
Linux fundamental - Chap 01 io
Kenny (netman)
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressions
Ben Brumfield
 
Linux fundamental - Chap 07 vi
Linux fundamental - Chap 07 viLinux fundamental - Chap 07 vi
Linux fundamental - Chap 07 vi
Kenny (netman)
 
Linux fundamental - Chap 03 file
Linux fundamental - Chap 03 fileLinux fundamental - Chap 03 file
Linux fundamental - Chap 03 file
Kenny (netman)
 
Linux fundamental - Chap 13 account management
Linux fundamental - Chap 13 account managementLinux fundamental - Chap 13 account management
Linux fundamental - Chap 13 account management
Kenny (netman)
 
Linux fundamental - Chap 09 pkg
Linux fundamental - Chap 09 pkgLinux fundamental - Chap 09 pkg
Linux fundamental - Chap 09 pkg
Kenny (netman)
 
Linux fundamental - Chap 02 perm
Linux fundamental - Chap 02 permLinux fundamental - Chap 02 perm
Linux fundamental - Chap 02 perm
Kenny (netman)
 
Importance of linux system fundamental in technical documentation reading
Importance of linux system fundamental in technical documentation readingImportance of linux system fundamental in technical documentation reading
Importance of linux system fundamental in technical documentation reading
Kenny (netman)
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
National Cheng Kung University
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line toolsEric Wilson
 
Linux.ppt
Linux.ppt Linux.ppt
Linux.ppt
onu9
 

Viewers also liked (20)

101 3.7 search text files using regular expressions
101 3.7 search text files using regular expressions101 3.7 search text files using regular expressions
101 3.7 search text files using regular expressions
 
101 3.7 search text files using regular expressions
101 3.7 search text files using regular expressions101 3.7 search text files using regular expressions
101 3.7 search text files using regular expressions
 
3, regular expression
3, regular expression3, regular expression
3, regular expression
 
Presentation at RegX on Business Model Innovation and Speed Creation 20120904
Presentation at RegX on Business Model Innovation and Speed Creation 20120904Presentation at RegX on Business Model Innovation and Speed Creation 20120904
Presentation at RegX on Business Model Innovation and Speed Creation 20120904
 
Windows7 Vs Linux
Windows7 Vs LinuxWindows7 Vs Linux
Windows7 Vs Linux
 
Linux fundamental - Chap 08 proc
Linux fundamental - Chap 08 procLinux fundamental - Chap 08 proc
Linux fundamental - Chap 08 proc
 
Linux CLI
Linux CLILinux CLI
Linux CLI
 
Linux fundamental - Chap 10 fs
Linux fundamental - Chap 10 fsLinux fundamental - Chap 10 fs
Linux fundamental - Chap 10 fs
 
The linux command line for total beginners
The linux command line  for total beginnersThe linux command line  for total beginners
The linux command line for total beginners
 
Linux fundamental - Chap 01 io
Linux fundamental - Chap 01 ioLinux fundamental - Chap 01 io
Linux fundamental - Chap 01 io
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressions
 
Linux fundamental - Chap 07 vi
Linux fundamental - Chap 07 viLinux fundamental - Chap 07 vi
Linux fundamental - Chap 07 vi
 
Linux fundamental - Chap 03 file
Linux fundamental - Chap 03 fileLinux fundamental - Chap 03 file
Linux fundamental - Chap 03 file
 
Linux fundamental - Chap 13 account management
Linux fundamental - Chap 13 account managementLinux fundamental - Chap 13 account management
Linux fundamental - Chap 13 account management
 
Linux fundamental - Chap 09 pkg
Linux fundamental - Chap 09 pkgLinux fundamental - Chap 09 pkg
Linux fundamental - Chap 09 pkg
 
Linux fundamental - Chap 02 perm
Linux fundamental - Chap 02 permLinux fundamental - Chap 02 perm
Linux fundamental - Chap 02 perm
 
Importance of linux system fundamental in technical documentation reading
Importance of linux system fundamental in technical documentation readingImportance of linux system fundamental in technical documentation reading
Importance of linux system fundamental in technical documentation reading
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
 
Linux.ppt
Linux.ppt Linux.ppt
Linux.ppt
 

Similar to Linux fundamental - Chap 06 regx

How to check valid Email? Find using regex.
How to check valid Email? Find using regex.How to check valid Email? Find using regex.
How to check valid Email? Find using regex.
Poznań Ruby User Group
 
Regular Expressions: JavaScript And Beyond
Regular Expressions: JavaScript And BeyondRegular Expressions: JavaScript And Beyond
Regular Expressions: JavaScript And Beyond
Max Shirshin
 
Unicode Regular Expressions
Unicode Regular ExpressionsUnicode Regular Expressions
Unicode Regular Expressions
Nova Patch
 
Quick start reg ex
Quick start reg exQuick start reg ex
Quick start reg ex
V krishnamoorthy
 
Lecture 3 RE NFA DFA
Lecture 3   RE NFA DFA Lecture 3   RE NFA DFA
Lecture 3 RE NFA DFA
Rebaz Najeeb
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentationarnolambert
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentationarnolambert
 
VIM for (PHP) Programmers
VIM for (PHP) ProgrammersVIM for (PHP) Programmers
VIM for (PHP) Programmers
ZendCon
 
Sdl Basic
Sdl BasicSdl Basic
Sdl Basic
roberto viola
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
Mahzad Zahedi
 
VIM for Programmers
VIM for ProgrammersVIM for Programmers
VIM for Programmers
Akash Agrawal
 
Linux shell
Linux shellLinux shell
Linux shell
Kenny (netman)
 
How to check valid Email? Find using regex.
How to check valid Email? Find using regex.How to check valid Email? Find using regex.
How to check valid Email? Find using regex.
Poznań Ruby User Group
 
Virtual Machine for Regular Expressions
Virtual Machine for Regular ExpressionsVirtual Machine for Regular Expressions
Virtual Machine for Regular Expressions
Alexander Yakushev
 
Perly Parsing with Regexp::Grammars
Perly Parsing with Regexp::GrammarsPerly Parsing with Regexp::Grammars
Perly Parsing with Regexp::Grammars
Workhorse Computing
 
Syntactic analysis in NLP
Syntactic analysis in NLPSyntactic analysis in NLP
Syntactic analysis in NLP
kartikaVashisht
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
Eran Zimbler
 

Similar to Linux fundamental - Chap 06 regx (20)

How to check valid Email? Find using regex.
How to check valid Email? Find using regex.How to check valid Email? Find using regex.
How to check valid Email? Find using regex.
 
Regular Expressions: JavaScript And Beyond
Regular Expressions: JavaScript And BeyondRegular Expressions: JavaScript And Beyond
Regular Expressions: JavaScript And Beyond
 
Unicode Regular Expressions
Unicode Regular ExpressionsUnicode Regular Expressions
Unicode Regular Expressions
 
Quick start reg ex
Quick start reg exQuick start reg ex
Quick start reg ex
 
Lecture 3 RE NFA DFA
Lecture 3   RE NFA DFA Lecture 3   RE NFA DFA
Lecture 3 RE NFA DFA
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
 
VIM for (PHP) Programmers
VIM for (PHP) ProgrammersVIM for (PHP) Programmers
VIM for (PHP) Programmers
 
Sdl Basic
Sdl BasicSdl Basic
Sdl Basic
 
Vim For Php
Vim For PhpVim For Php
Vim For Php
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
VIM for Programmers
VIM for ProgrammersVIM for Programmers
VIM for Programmers
 
Linux shell
Linux shellLinux shell
Linux shell
 
How to check valid Email? Find using regex.
How to check valid Email? Find using regex.How to check valid Email? Find using regex.
How to check valid Email? Find using regex.
 
Virtual Machine for Regular Expressions
Virtual Machine for Regular ExpressionsVirtual Machine for Regular Expressions
Virtual Machine for Regular Expressions
 
Perly Parsing with Regexp::Grammars
Perly Parsing with Regexp::GrammarsPerly Parsing with Regexp::Grammars
Perly Parsing with Regexp::Grammars
 
Ruby training day1
Ruby training day1Ruby training day1
Ruby training day1
 
Syntactic analysis in NLP
Syntactic analysis in NLPSyntactic analysis in NLP
Syntactic analysis in NLP
 
Vim
VimVim
Vim
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 

More from Kenny (netman)

rpi_audio configuration steps
rpi_audio configuration stepsrpi_audio configuration steps
rpi_audio configuration steps
Kenny (netman)
 
Rpi audio
Rpi audioRpi audio
Rpi audio
Kenny (netman)
 
Ha opensuse
Ha opensuseHa opensuse
Ha opensuse
Kenny (netman)
 
Chap 19 web
Chap 19 webChap 19 web
Chap 19 web
Kenny (netman)
 
Chap 18 net
Chap 18 netChap 18 net
Chap 18 net
Kenny (netman)
 
About the Course
About the CourseAbout the Course
About the Course
Kenny (netman)
 
Linux fundamental - Chap 16 System Rescue
Linux fundamental - Chap 16 System RescueLinux fundamental - Chap 16 System Rescue
Linux fundamental - Chap 16 System Rescue
Kenny (netman)
 
Linux fundamental - Chap 15 Job Scheduling
Linux fundamental - Chap 15 Job SchedulingLinux fundamental - Chap 15 Job Scheduling
Linux fundamental - Chap 15 Job Scheduling
Kenny (netman)
 
Linux fundamental - Chap 12 Hardware Management
Linux fundamental - Chap 12 Hardware ManagementLinux fundamental - Chap 12 Hardware Management
Linux fundamental - Chap 12 Hardware Management
Kenny (netman)
 
Linux fundamental - Chap 11 boot
Linux fundamental - Chap 11 bootLinux fundamental - Chap 11 boot
Linux fundamental - Chap 11 boot
Kenny (netman)
 
Linux fundamental - Chap 04 archive
Linux fundamental - Chap 04 archiveLinux fundamental - Chap 04 archive
Linux fundamental - Chap 04 archive
Kenny (netman)
 
Linux fundamental - Chap 00 shell
Linux fundamental - Chap 00 shellLinux fundamental - Chap 00 shell
Linux fundamental - Chap 00 shell
Kenny (netman)
 
Linux system security
Linux system securityLinux system security
Linux system security
Kenny (netman)
 
Linux network monitoring hands-on pratice
Linux network monitoring hands-on praticeLinux network monitoring hands-on pratice
Linux network monitoring hands-on pratice
Kenny (netman)
 
Linux Network Monitoring
Linux Network MonitoringLinux Network Monitoring
Linux Network Monitoring
Kenny (netman)
 
加密應用(GPG)
加密應用(GPG)加密應用(GPG)
加密應用(GPG)
Kenny (netman)
 
金鑰管理 (PKI)
金鑰管理 (PKI)金鑰管理 (PKI)
金鑰管理 (PKI)
Kenny (netman)
 
Linux firewall
Linux firewallLinux firewall
Linux firewall
Kenny (netman)
 

More from Kenny (netman) (19)

rpi_audio configuration steps
rpi_audio configuration stepsrpi_audio configuration steps
rpi_audio configuration steps
 
Rpi audio
Rpi audioRpi audio
Rpi audio
 
Ha opensuse
Ha opensuseHa opensuse
Ha opensuse
 
Chap 19 web
Chap 19 webChap 19 web
Chap 19 web
 
Chap 18 net
Chap 18 netChap 18 net
Chap 18 net
 
Chap 17 advfs
Chap 17 advfsChap 17 advfs
Chap 17 advfs
 
About the Course
About the CourseAbout the Course
About the Course
 
Linux fundamental - Chap 16 System Rescue
Linux fundamental - Chap 16 System RescueLinux fundamental - Chap 16 System Rescue
Linux fundamental - Chap 16 System Rescue
 
Linux fundamental - Chap 15 Job Scheduling
Linux fundamental - Chap 15 Job SchedulingLinux fundamental - Chap 15 Job Scheduling
Linux fundamental - Chap 15 Job Scheduling
 
Linux fundamental - Chap 12 Hardware Management
Linux fundamental - Chap 12 Hardware ManagementLinux fundamental - Chap 12 Hardware Management
Linux fundamental - Chap 12 Hardware Management
 
Linux fundamental - Chap 11 boot
Linux fundamental - Chap 11 bootLinux fundamental - Chap 11 boot
Linux fundamental - Chap 11 boot
 
Linux fundamental - Chap 04 archive
Linux fundamental - Chap 04 archiveLinux fundamental - Chap 04 archive
Linux fundamental - Chap 04 archive
 
Linux fundamental - Chap 00 shell
Linux fundamental - Chap 00 shellLinux fundamental - Chap 00 shell
Linux fundamental - Chap 00 shell
 
Linux system security
Linux system securityLinux system security
Linux system security
 
Linux network monitoring hands-on pratice
Linux network monitoring hands-on praticeLinux network monitoring hands-on pratice
Linux network monitoring hands-on pratice
 
Linux Network Monitoring
Linux Network MonitoringLinux Network Monitoring
Linux Network Monitoring
 
加密應用(GPG)
加密應用(GPG)加密應用(GPG)
加密應用(GPG)
 
金鑰管理 (PKI)
金鑰管理 (PKI)金鑰管理 (PKI)
金鑰管理 (PKI)
 
Linux firewall
Linux firewallLinux firewall
Linux firewall
 

Recently uploaded

Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 

Recently uploaded (20)

Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 

Linux fundamental - Chap 06 regx

  • 1. Chapter 6Chapter 6 Regular ExpressionRegular Expression Ref. Pge. 32
  • 2. Regular ExpressionRegular Expression ● Processing in line baseProcessing in line base ● Meta characters may conflict with shell,Meta characters may conflict with shell, must be quotedmust be quoted ● Commonly used in text filtering:Commonly used in text filtering: – grep, sed, awk, perl, php, etc...grep, sed, awk, perl, php, etc...
  • 3. Character setCharacter set ● The way to treat character:The way to treat character: abcabc :: individual characterindividual character (abc)(abc) :: a set of charactera set of character (abc|xyz)(abc|xyz) :: one set ofone set of [abc][abc] :: one character of listone character of list [^abc][^abc] :: one character of non-listone character of non-list
  • 4. Anchor CharactersAnchor Characters ● The position in a line:The position in a line: ^^ : the beginning of line: the beginning of line $$ : the end of line: the end of line << : the beginning of word: the beginning of word >> :: the end of wordthe end of word
  • 5. ModifierModifier ● To modify existence of the precedingTo modify existence of the preceding character or set:character or set: ** :: zero or more timeszero or more times ?? :: zero or one timeszero or one times ++ :: one or more timesone or more times {n}{n} :: nn timestimes {n,m}{n,m} :: nn toto mm timestimes
  • 6. BoundaryBoundary ● Anything outside the boundary is ignoredAnything outside the boundary is ignored ● Which of following matchWhich of following match abc{3,5}abc{3,5}?? aabccbcc abccccabcccc abccccccabcccccc
  • 7. ANSWERANSWER ● TheThe abc{3,5}abc{3,5} doesn't care about whatdoesn't care about what character following thecharacter following the 5th5th c :c : abcccccabccccccc
  • 8. RE VersionRE Version ● Extended and traditional:Extended and traditional: ExtendedExtended TraditionalTraditional ++ ++ ?? ?? ()() ()() {}{} {}{} || (none)(none)
  • 9. UsingUsing grepgrep ● grep 'RE' text.filegrep 'RE' text.file – Display all lines matching REDisplay all lines matching RE – Common optionsCommon options ● ­E­E : use extended version of RE: use extended version of RE ● ­i­i : ignore case: ignore case ● ­v­v : revers behavior: revers behavior ● ­n­n : show line number: show line number ● ­c­c : show matching counter: show matching counter ● ­l­l : show file name only: show file name only ● ­r­r : recursively search directory: recursively search directory ● ­q­q : silent mode: silent mode Ref. Pge. 33
  • 10. UsingUsing sedsed ● sed <cmd> text.filesed <cmd> text.file cmd=[address]cmdcmd=[address]cmd – AddressAddress ● <none><none> : all lines: all lines ● nn,,mm : lines from: lines from nn toto mm ($ represents the last line)($ represents the last line) ● /RE//RE/ : lines match RE: lines match RE ● /RE1/,/RE2//RE1/,/RE2/ : lines from matching RE1 to RE2: lines from matching RE1 to RE2 Ref. Pge. 35
  • 11. UsingUsing sedsed ● CommonCommon sedsed commands:commands: ii : insert a line above: insert a line above aa : append a line bellow: append a line bellow cc : change the match lines: change the match lines dd : delete the match lines: delete the match lines
  • 12. UsingUsing sedsed ● TheThe ss command:command: – s/RE/string/[flag]s/RE/string/[flag] ● Substitute the first RE in a line to stringSubstitute the first RE in a line to string ● Flags:Flags: – nn : substitute the: substitute the nnth RE onlyth RE only – gg : substitute the all REs: substitute the all REs – ii : ignore case: ignore case – s/RE/&string/s/RE/&string/ ● keep RE at position &keep RE at position & – ss//(RE1)...(RE2)(RE1)...(RE2)//1string21string2// ● keep RE1 at position 1 and RE2 at position 2, and sokeep RE1 at position 1 and RE2 at position 2, and so on...on...
  • 13. UsingUsing awkawk ● awk 'program' text.fileawk 'program' text.file – Common options:Common options: ● ­F s­F s : specify field separators (one or more): specify field separators (one or more) ● ­v var=value­v var=value : set variable: set variable ● ­f file­f file : read program from file: read program from file
  • 14. UsingUsing awkawk ● Program structure:Program structure: expression {action}expression {action} – Expression:Expression: ● /RE//RE/ ● if ( ) statementif ( ) statement ● while ( ) statementwhile ( ) statement ● for ( ) statementfor ( ) statement
  • 15. UsingUsing awkawk – Common actions:Common actions: ● print $<POS>print $<POS> : print position (whole line: 0): print position (whole line: 0) ● printf <format>printf <format> : print in specified format: print in specified format ● <arithmetic functions><arithmetic functions> : do calculation: do calculation ● <string functions><string functions> : process string: process string ● Many more...Many more...