SlideShare una empresa de Scribd logo
1 de 15
Descargar para leer sin conexión
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...

Más contenido relacionado

La actualidad más candente

Debugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB TricksDebugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB Tricks
dutor
 

La actualidad más candente (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
 

Destacado

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
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
Eric Wilson
 

Destacado (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 a Linux fundamental - Chap 06 regx

Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
arnolambert
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
arnolambert
 

Similar a 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
 

Más de Kenny (netman)

Más de 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
 

Último

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Último (20)

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet 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...