Browse Source

grep 8

master
zeus 4 years ago
parent
commit
4f266f20a9
  1. 2
      grep/0_Case_insensitive_search/code
  2. 2
      grep/1_Displaying_info/code
  3. 10
      grep/3_Regular_Expressions_Examples/code
  4. 2
      grep/3_Regular_Expressions_Examples/codeanswer
  5. 1
      grep/3_Regular_Expressions_Examples/codehelp
  6. 24692
      grep/3_Regular_Expressions_Examples/data
  7. 76
      grep/3_Regular_Expressions_Examples/info
  8. 28
      grep/3_Regular_Expressions_Examples/q-info

2
grep/0_Case_insensitive_search/code

@ -1 +1 @@
grep -i "Jordan" $LLO_DATAFILE | head -15
grep -i "Jordan" $LLO_DATAFILE | head -5

2
grep/1_Displaying_info/code

@ -1,3 +1,3 @@
grep -c "Jordan" $LLO_DATAFILE
echo " Prefix each line of output with the 1-based line number within its input file."
grep -n "Jordan" $LLO_DATAFILE | tail -15
grep -n "Jordan" $LLO_DATAFILE | tail -5

10
grep/3_Regular_Expressions_Examples/code

@ -0,0 +1,10 @@
grep '[Jj][oO][rR][dD][aA][nN]' $LLO_DATAFILE
grep '\<b.t\>' $LLO_DATAFILE
grep -E 'Michael Jordan|Eddie Jordan' $LLO_DATAFILE
grep '199[0-9]' $LLO_DATAFILE | grep -E "Kukoc|Jordan"

2
grep/3_Regular_Expressions_Examples/codeanswer

@ -0,0 +1,2 @@
grep "Jordan" $LLO_DATAFILE | grep -v Edd | grep Michae | grep 199[0,1,2]

1
grep/3_Regular_Expressions_Examples/codehelp

@ -0,0 +1 @@
echo "Try grep --help\n cat --help \n cut --help"

24692
grep/3_Regular_Expressions_Examples/data

File diff suppressed because it is too large

76
grep/3_Regular_Expressions_Examples/info

@ -0,0 +1,76 @@
The grep understands three different types of regular expression syntax as follows:
- basic (BRE)
- extended (ERE)
- perl (PCRE)
Examples
The dot (.) matches any single character. You can match specific characters and character ranges using [..] syntax.
[source,sh]
----
grep "Jordan" $LLO_DATAFILE | grep "\,199.\,M"
----
INFO: You can escape the dot (.) by preceding it with a \ (backslash)
Say you want to Match both ‘Jordan’ or ‘jordan’:
[source,sh]
----
grep '[Jj]ordan' $LLO_DATAFILE
----
OR
[source,sh]
----
grep '[Jj][oO][rR][dD][aA][nN]' $LLO_DATAFILE
----
[source,sh]
----
grep '\<b.t\>' $LLO_DATAFILE
----
Where,
- \< Match the empty string at the beginning of word
- \> Match the empty string at the end of word.
Do *OR* with grep
[source,sh]
----
grep -E 'Michael Jordan|Eddie Jordan' $LLO_DATAFILE
----
Do *AND* with grep
[source,sh]
----
grep '199[0-9]' $LLO_DATAFILE | grep -E "Kukoc|Jordan"
----
[INFO]
====
DATAFILE
The datafile contains aggregate individual statistics for 67 NBA seasons. from basic box-score attributes such as points, assists, rebounds etc., to more advanced money-ball like features such as Value Over Replacement.
Take a look in
link:https://git.swarmlab.io:3000/llo/LabLearningObject/src/branch/master/data/nba_statistics_glossary[Glossary^]
for a detailed column description
ENVIRONMENT VARIABLE: LLO_DATAFILE
====

28
grep/3_Regular_Expressions_Examples/q-info

@ -0,0 +1,28 @@
Try to find
- 1995-96 Chicago Bulls Roster
- 2-Point Field Goal Percentage
- Optional: Jordans Assists
[source,sh]
----
No. Player Pos
0 Randy Brown PG
30 Jud Buechler SF
35 Jason Caffey PF
53 James Edwards C
54 Jack Haley C
9 Ron Harper PG
23 Michael Jordan SG
25 Steve Kerr PG
7 Toni Kukoč SF
13 Luc Longley C
33 Scottie Pippen SF
91 Dennis Rodman PF
22 John Salley PF
8 Dickey Simpkins PF
34 Bill Wennington C
----
Loading…
Cancel
Save