SlideShare a Scribd company logo
1 of 17
PERL
File Handling and Regex
FH – Opening a File

Opening a file :
open(file handler, filename);

3 Modes : Read, Write and Append

To open file in write mode
open(FH, >myfile.txt);

To open file in append mode
open(FH, >>myfile.txt);

Error handling
open(FH, myfile.txt) or die(“Could not open file : $! n”);

To read from File Handler
@filearr = <FH>;
FH – Writing to a File

Writing a statement to a file.
Print FH (“Writing to the filen”);

Closing a file
close(FH);

Perl automatically calls close, if we do not specify.
FH - seek

The seek function moves backward or forword in a file.
seek(FH, distance, relative_to);
distance is number of bytes to skip
relative_to could be either 0, 1 or 2
0 => From beginning of file
1 => From current position
2 => From end of file
FH – tell, read

Tell : Returns the distance, in bytes, between the beginning of the file and
the current position of the file.
tell(FH);

Read : enables us to read an aribtrary number of characters into a scalar
variable.
read(FH, result, length, offset);
result is the scalar variable into which the bytes are to be stored
lenght is the number of bytes to read
offset may be specified to place the read data at some place other than
beginning. A negative offset means, that many characters from end in
backward, a positive offset means that many from beginning forward.

read(FH,$scalar,80); # reads 80 bytes from the file represented by FH,
storing the resulting character string in $scalar
FH – other functions
getc : Reads a single character of input from file
$singlechar = getc(FH);

binmode : Tell the system that the file is a binary file. It must be called
after the file is opened and before read.
binmode(FH);

rename : Renames a file.
rename(oldname, newname);

unlink : Delete the file.
$num = unlink(@filelists); # It returns the number of files deleted.

mkdir : create directory
mkdir(“dirname”, permissions);

chdir(dirname) : Set the current working directory

rmdir(dirname) : Deletes an empty directory
FH – HERE docs

Print <<FH;
Hello I am here.
Welcome.
Bye.
FH
Regular Expressions
Basic RE

A regular expression is contained in slashes, and
matching occurs with the =~ operator. The following
expression is true if the string the appears in variable
$sentence.
$sentence =~ /the/

The RE is case sensitive, so if
$sentence = "The quick brown fox";
then the above match will be false.

The operator !~ is used for spotting a non-match. In
Special RE Characters
. # Any single character except a newline
^ # The beginning of the line or string
$ # The end of the line or string
* # Zero or more of the last character
+ # One or more of the last character
? # Zero or one of the last character
RE match examples

t.e # t followed by anthing followed by e
# This will match the
tre
tle
but not te, tale

^f# f at the beginning of a line

^ftp # ftp at the beginning of a line

e$ # e at the end of a line

tle$ # tle at the end of a line
RE match examples

and* # an followed by zero or more d characters
# This will match an
and
andd
anddd (etc)

.* # Any string without a newline. This is because the .
matches anything except a newline and the * means
zero or more of these.

^$ # A line with nothing in it.
More on RE

[qjk] # Either q or j or k

[^qjk] # Neither q nor j nor k

[a-z] # Anything from a to z inclusive

[^a-z] # No lower case letters

[a-zA-Z] # Any letter

[a-z]+ # Any non-zero sequence of lower case
letters

jelly|jam # Either jelly or jam

(eg|le)gs # Either eggs or legs

RE Special Characters

n # A newline

t # A tab

w # Any alphanumeric (word) character.
same as [a-zA-Z0-9_]

W # Any non-word character. same as [^a-
zA-Z0-9_]

d # Any digit, same as [0-9]

D # Any non-digit, same as [^0-9]

s # Any whitespace character: space, tab,
newline, etc
Substitution

To replace an occurrence of london by London in the
string $sentence we use the expression
$sentence =~ s/hello/Hello/

This example only replaces the first occurrence of the
string, and it may be that there will be more than one
such string we want to replace. To make a global
substitution the last slash is followed by a g as follows:
$sentence =~ s/hello/Hello/g

To ignore case and substitute.
$sentence =~ s/hello/Hello/gi
Translation

The tr function allows character-by-character
translation. The following expression replaces each a
with e, each b with d, and each c with f in the variable
$sentence. The expression returns the number of
substitutions made.
$sentence =~ tr/abc/edf/

To convert lower case to upper case
tr/a-z/A-Z/;
Remembering Patterns

remember patterns that have been matched so that
they can be used again.

anything matched in parentheses gets remembered in
the variables $1,...,$9.

These strings can also be used in the same regular
expression (or substitution) by using the special RE
codes 1,...,9.

More Related Content

What's hot (20)

HMM (Hidden Markov Model)
HMM (Hidden Markov Model)HMM (Hidden Markov Model)
HMM (Hidden Markov Model)
 
Scop database
Scop databaseScop database
Scop database
 
Sql fundamentals
Sql fundamentalsSql fundamentals
Sql fundamentals
 
encode project
encode project encode project
encode project
 
Tech Talk: UCSC Genome Browser
Tech Talk: UCSC Genome BrowserTech Talk: UCSC Genome Browser
Tech Talk: UCSC Genome Browser
 
Introduction to databases.pptx
Introduction to databases.pptxIntroduction to databases.pptx
Introduction to databases.pptx
 
Fasta
FastaFasta
Fasta
 
blast bioinformatics
blast bioinformaticsblast bioinformatics
blast bioinformatics
 
Bioinformatics and BioPerl
Bioinformatics and BioPerlBioinformatics and BioPerl
Bioinformatics and BioPerl
 
Primary and secondary databases ppt by puneet kulyana
Primary and secondary databases ppt by puneet kulyanaPrimary and secondary databases ppt by puneet kulyana
Primary and secondary databases ppt by puneet kulyana
 
Proteins databases
Proteins databasesProteins databases
Proteins databases
 
Ensembl genome
Ensembl genomeEnsembl genome
Ensembl genome
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
 
Protein database
Protein databaseProtein database
Protein database
 
Data mining
Data miningData mining
Data mining
 
Thread priorities
Thread prioritiesThread priorities
Thread priorities
 
Mitochondria and chloroplast structure and genome organisation
Mitochondria and chloroplast structure and genome organisationMitochondria and chloroplast structure and genome organisation
Mitochondria and chloroplast structure and genome organisation
 
Protein Data Bank
Protein Data BankProtein Data Bank
Protein Data Bank
 
Protein databases
Protein databasesProtein databases
Protein databases
 
Introduction to NCBI
Introduction to NCBIIntroduction to NCBI
Introduction to NCBI
 

Similar to Perl File Handling and Regex

Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell ScriptDr.Ravi
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1Dr.Ravi
 
Unix command line concepts
Unix command line conceptsUnix command line concepts
Unix command line conceptsArtem Nagornyi
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsRoy Zimmer
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHBhavsingh Maloth
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on LinuxTushar B Kute
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Andrea Telatin
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptxNiladriDey18
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Perl courseparti
Perl coursepartiPerl courseparti
Perl coursepartiernlow
 

Similar to Perl File Handling and Regex (20)

Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1
 
Unix command line concepts
Unix command line conceptsUnix command line concepts
Unix command line concepts
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on Linux
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
 
Perl
PerlPerl
Perl
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptx
 
groovy & grails - lecture 3
groovy & grails - lecture 3groovy & grails - lecture 3
groovy & grails - lecture 3
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Perl courseparti
Perl coursepartiPerl courseparti
Perl courseparti
 
First steps in PERL
First steps in PERLFirst steps in PERL
First steps in PERL
 

Recently uploaded

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
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 . pdfQucHHunhnh
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
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...christianmathematics
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 

Recently uploaded (20)

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
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
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 

Perl File Handling and Regex

  • 2. FH – Opening a File  Opening a file : open(file handler, filename);  3 Modes : Read, Write and Append  To open file in write mode open(FH, >myfile.txt);  To open file in append mode open(FH, >>myfile.txt);  Error handling open(FH, myfile.txt) or die(“Could not open file : $! n”);  To read from File Handler @filearr = <FH>;
  • 3. FH – Writing to a File  Writing a statement to a file. Print FH (“Writing to the filen”);  Closing a file close(FH);  Perl automatically calls close, if we do not specify.
  • 4. FH - seek  The seek function moves backward or forword in a file. seek(FH, distance, relative_to); distance is number of bytes to skip relative_to could be either 0, 1 or 2 0 => From beginning of file 1 => From current position 2 => From end of file
  • 5. FH – tell, read  Tell : Returns the distance, in bytes, between the beginning of the file and the current position of the file. tell(FH);  Read : enables us to read an aribtrary number of characters into a scalar variable. read(FH, result, length, offset); result is the scalar variable into which the bytes are to be stored lenght is the number of bytes to read offset may be specified to place the read data at some place other than beginning. A negative offset means, that many characters from end in backward, a positive offset means that many from beginning forward.  read(FH,$scalar,80); # reads 80 bytes from the file represented by FH, storing the resulting character string in $scalar
  • 6. FH – other functions getc : Reads a single character of input from file $singlechar = getc(FH);  binmode : Tell the system that the file is a binary file. It must be called after the file is opened and before read. binmode(FH);  rename : Renames a file. rename(oldname, newname);  unlink : Delete the file. $num = unlink(@filelists); # It returns the number of files deleted.  mkdir : create directory mkdir(“dirname”, permissions);  chdir(dirname) : Set the current working directory  rmdir(dirname) : Deletes an empty directory
  • 7. FH – HERE docs  Print <<FH; Hello I am here. Welcome. Bye. FH
  • 9. Basic RE  A regular expression is contained in slashes, and matching occurs with the =~ operator. The following expression is true if the string the appears in variable $sentence. $sentence =~ /the/  The RE is case sensitive, so if $sentence = "The quick brown fox"; then the above match will be false.  The operator !~ is used for spotting a non-match. In
  • 10. Special RE Characters . # Any single character except a newline ^ # The beginning of the line or string $ # The end of the line or string * # Zero or more of the last character + # One or more of the last character ? # Zero or one of the last character
  • 11. RE match examples  t.e # t followed by anthing followed by e # This will match the tre tle but not te, tale  ^f# f at the beginning of a line  ^ftp # ftp at the beginning of a line  e$ # e at the end of a line  tle$ # tle at the end of a line
  • 12. RE match examples  and* # an followed by zero or more d characters # This will match an and andd anddd (etc)  .* # Any string without a newline. This is because the . matches anything except a newline and the * means zero or more of these.  ^$ # A line with nothing in it.
  • 13. More on RE  [qjk] # Either q or j or k  [^qjk] # Neither q nor j nor k  [a-z] # Anything from a to z inclusive  [^a-z] # No lower case letters  [a-zA-Z] # Any letter  [a-z]+ # Any non-zero sequence of lower case letters  jelly|jam # Either jelly or jam  (eg|le)gs # Either eggs or legs 
  • 14. RE Special Characters  n # A newline  t # A tab  w # Any alphanumeric (word) character. same as [a-zA-Z0-9_]  W # Any non-word character. same as [^a- zA-Z0-9_]  d # Any digit, same as [0-9]  D # Any non-digit, same as [^0-9]  s # Any whitespace character: space, tab, newline, etc
  • 15. Substitution  To replace an occurrence of london by London in the string $sentence we use the expression $sentence =~ s/hello/Hello/  This example only replaces the first occurrence of the string, and it may be that there will be more than one such string we want to replace. To make a global substitution the last slash is followed by a g as follows: $sentence =~ s/hello/Hello/g  To ignore case and substitute. $sentence =~ s/hello/Hello/gi
  • 16. Translation  The tr function allows character-by-character translation. The following expression replaces each a with e, each b with d, and each c with f in the variable $sentence. The expression returns the number of substitutions made. $sentence =~ tr/abc/edf/  To convert lower case to upper case tr/a-z/A-Z/;
  • 17. Remembering Patterns  remember patterns that have been matched so that they can be used again.  anything matched in parentheses gets remembered in the variables $1,...,$9.  These strings can also be used in the same regular expression (or substitution) by using the special RE codes 1,...,9.