Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GoikLectures
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Goik Martin
GoikLectures
Commits
d45e8306
Commit
d45e8306
authored
8 years ago
by
Goik Martin
Browse files
Options
Downloads
Patches
Plain Diff
Small extension hint
parent
1133eeee
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Doc/Sd1/appendix.xml
+80
-10
80 additions, 10 deletions
Doc/Sd1/appendix.xml
with
80 additions
and
10 deletions
Doc/Sd1/appendix.xml
+
80
−
10
View file @
d45e8306
...
...
@@ -313,13 +313,13 @@
<title>
Poor man's
<xref
linkend=
"glo_UNIX"
/>
<command
xlink:href=
"http://linux.die.net/man/1/grep"
>
grep
</command>
.
</title>
<para>
The
<xref
linkend=
"glo_UNIX"
/>
operating system provides
the
<para>
The
<xref
linkend=
"glo_UNIX"
/>
operating system provides
a command
<command
xlink:href=
"http://linux.die.net/man/1/grep"
>
grep
</command>
command
which allows for retrieving occurrences of given string
s
in text
files.
We consider an example text file
<filename>
input.txt
</filename>
which allows for retrieving occurrences of
a
given string in text
files.
We consider an example text file
<filename>
input.txt
</filename>
containing four lines:
</para>
<programlisting
language=
"none"
linenumbering=
"
un
numbered"
>
Roses are nice flowers.
<programlisting
language=
"none"
linenumbering=
"numbered"
>
Roses are nice flowers.
Red wine is tasty
The red cross acts worldwide
Mayflower used to be a ship.
</programlisting>
...
...
@@ -328,7 +328,7 @@ Mayflower used to be a ship.</programlisting>
occurrence of the string
<quote>
flower
</quote>
being contained in lines
1 and 4:
</para>
<programlisting
language=
"none"
>
>
grep
<emphasis
role=
"bold"
>
flower
</emphasis>
input.txt
<programlisting
language=
"none"
>
>
grep
<emphasis
role=
"bold"
>
flower
</emphasis>
input.txt
Roses are nice
<emphasis
role=
"bold"
>
flower
</emphasis>
s.
May
<emphasis
role=
"bold"
>
flower
</emphasis>
used to be a ship.
</programlisting>
...
...
@@ -338,18 +338,88 @@ May<emphasis role="bold">flower</emphasis> used to be a ship.</programlisting>
output. Adding the command line option
<option>
-i
</option>
allows for
case insensitive searches:
</para>
<programlisting
language=
"none"
linenumbering=
"unnumbered"
>
>
grep
<option>
-i
</option>
<emphasis
role=
"bold"
>
red
</emphasis>
input.txt
<programlisting
language=
"none"
linenumbering=
"unnumbered"
>
>
grep
<option>
-i
</option>
<emphasis
role=
"bold"
>
red
</emphasis>
input.txt
<emphasis
role=
"bold"
>
Red
</emphasis>
wine is tasty
The
<emphasis
role=
"bold"
>
red
</emphasis>
cross acts worldwide
</programlisting>
<para>
This time all possible variants like
<quote>
Red
</quote>
,
<quote>
red
</quote>
,
<quote>
RED
</quote>
and so on will match.
</para>
<quote>
red
</quote>
,
<quote>
RED
</quote>
and so on will match.
</para>
<para><command
xlink:href=
"http://linux.die.net/man/1/grep"
>
grep
</command>
also allows
for searching multiple files. Consider another text file
second.txt:
</para>
for searching multiple files. Consider a second file
<filename>
inputSecond.txt
</filename>
:
</para>
<programlisting
language=
"none"
linenumbering=
"numbered"
>
Errors will show up in red.
Let's start bug fixing
</programlisting>
<para>
We may search for case insensitive (
<option>
-i
</option>
again)
appearances of
<quote>
red
</quote>
within both files:
</para>
<programlisting
language=
"none"
linenumbering=
"unnumbered"
>
>
grep -i
<emphasis
role=
"bold"
>
red
</emphasis>
input.txt inputSecond.txt
input.txt:
<emphasis
role=
"bold"
>
Red
</emphasis>
wine is tasty
input.txt:The
<emphasis
role=
"bold"
>
red
</emphasis>
cross acts worldwide
inputSecond.txt:Errors will show up in
<emphasis
role=
"bold"
>
red
</emphasis>
.
</programlisting>
<para>
Finally the
<option>
-l
</option>
option will filter individual
appearances just showing filenames containing matches:
</para>
<programlisting
language=
"none"
>
>
grep -l Red input.txt inputSecond.txt
input.txt
</programlisting>
<para>
In contrast a case insensitive search combining both
<option>
-i
</option>
and
<option>
-l
</option>
options yields:
</para>
<programlisting
language=
"none"
>
>
grep -i -l Red input.txt inputSecond.txt
input.txt
inputSecond.txt
</programlisting>
<para>
The
<command
xlink:href=
"http://linux.die.net/man/1/grep"
>
grep
</command>
command may
read its input from standard input allowing for
<link
xlink:href=
"https://en.wikipedia.org/wiki/Pipeline_(Unix)"
>
pipes
</link>
.
This way another command's output feeds into a subsequently executed
command. As an example consider a recursive search for HTML files using
the
<link
xlink:href=
"http://linux.die.net/man/1/find"
>
find
</link>
command:
</para>
<programlisting
language=
"none"
>
>
find . -name \*.html
./Sd1/Wc/wc/Testdata/input.html
./Sda1/rdbmsXml2Html/TestData/climbingprice.html
./Sda1/NoCast/src/main/resources/gallery.html
./Sda1/Jdom/Html2Html/src/main/resources/imageExampleNew.html
./Sda1/Jdom/Html2Html/src/main/resources/imageExample.html
./Sda1/VerifyImgAccess/fileextref.html
</programlisting>
<para>
We want to restrict the above list to pathnames containing the
string
<quote>
Example
</quote>
. This may be achieved by
<link
xlink:href=
"https://en.wikipedia.org/wiki/Pipeline_(Unix)"
>
piping
</link>
the
<link
xlink:href=
"http://linux.die.net/man/1/find"
>
find
</link>
command's output as input to
<command
xlink:href=
"http://linux.die.net/man/1/grep"
>
grep
</command>
searching
for the occurrence of the string
<quote>
Example
</quote>
. Technically
both processes get connected by means of the pipe symbol
<quote>
|
</quote>
:
</para>
<programlisting
language=
"none"
>
>
find . -name \*.html|grep Example
./Sda1/Jdom/Html2Html/src/main/resources/imageExampleNew.html
./Sda1/Jdom/Html2Html/src/main/resources/imageExample.html
</programlisting>
<tip>
<para/>
<orderedlist>
<listitem>
<para/>
</listitem>
<listitem>
<para/>
</listitem>
</orderedlist>
</tip>
</section>
<section
xml:id=
"sd1ProjectSieveErathostenes"
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment