Skip to content

Commit

Permalink
updates for version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
learnbyexample committed Apr 13, 2020
1 parent 0024dae commit 229a30a
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 67 deletions.
6 changes: 6 additions & 0 deletions code_snippets/Adding_content_from_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ printf '%b' "$items" | sed -e '2 {r /dev/stdin' -e 'd}' ip.txt

sed -e '/^red/r ip.txt' -e '/yellow/,//d' fav_colors.txt

sed '/red/e cat ip.txt' fav_colors.txt

text='good\tone\nfood\tpun'

echo "$text" | sed '1e cat /dev/stdin' ip.txt

sed '/red/R ip.txt' fav_colors.txt

seq 4 | sed 'R /dev/stdin' fav_colors.txt
Expand Down
10 changes: 10 additions & 0 deletions code_snippets/BRE_ERE_Regular_Expressions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ echo 'foot' | sed -E 's/f.?o/X/'

echo 'car bat cod map scat dot abacus' | sed 's/.*/X/'

echo 'foo123312baz' | sed -E 's/o(1|2|3)+(12baz)?/X/'

echo 'foo123312baz' | perl -pe 's/o(1|2|3)+(12baz)?/X/'

echo 'car bat cod map scat dot abacus' | sed 's/.*m/-/'

echo 'car bat cod map scat dot abacus' | sed 's/b.*t/-/'
Expand Down Expand Up @@ -188,6 +192,12 @@ echo "universe: '42'" | sed 's/\x27/"/g'

echo 'universe: "42"' | sed 's/"/\x27/g'

printf 'cute\ncot\ncat\ncoat\n' | sed -n '/\x5eco/p'

echo 'hello world' | sed 's/.*/"&"/'

echo 'hello world' | sed 's/.*/"\x26"/'

echo 'effort flee facade oddball rat tool' | sed -E 's/\w*(\w)\1\w*/X/g'

echo '\[\] and \\w and \[a-zA-Z0-9\_\]' | sed -E 's/(\\?)\\/\1/g'
Expand Down
4 changes: 4 additions & 0 deletions code_snippets/Control_structures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ sed '/^-/{s///; b}; s/^/-/' nums.txt

sed '/^-/ s///; t; s/^/-/' nums.txt

printf 'good\nbad\n' | sed 's/o/-/g; T; s/d/*/g'

printf 'good\nbad\nneed\n' | sed 's/o/-/g; s/a/%/g; T; a ----'

echo '12345 hello42' | sed -E ':a s/^(\**)[0-9]/\1*/; ta'

echo '123x45 hello42' | sed -E ':a s/^(\**)[0-9]/\1*/; ta'
Expand Down
6 changes: 1 addition & 5 deletions code_snippets/Flags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ printf 'date\ndate -I\n' | sed '/date/e'

printf 'date\ndate -I\n' | sed '2e'

printf 'date\ndate -I\n' > dates.txt

sed -i '/date/e' dates.txt

cat dates.txt
printf 'show\nexample\n' | sed '/am/e seq 2'

printf 'Hi there\nHave a Nice Day\n' | sed 'N; s/H.*e/X/'

Expand Down
20 changes: 19 additions & 1 deletion code_snippets/Shell_substitutions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ c1=${c//&/\\&}

echo 'a and b and c' | sed 's/and/'"${c1}"'/g'

r='a/b&c\d'

r=$(printf '%s' "$r" | sed 's#[\&/]#\\&#g')

s='{[(\ta^b/d).*+?^$|]}'

s=$(printf '%s' "$s" | sed 's#[{[()^$*?+.\|/]#\\&#g')

echo 'f*{[(\ta^b/d).*+?^$|]} - 3' | sed -E 's/'"$s"'/'"$r"'/g'

s='{[(\ta^b/d).*+?^$|]}'

s=$(printf '%s' "$s" | sed 's#[[^$*.\/]#\\&#g')

echo 'f*{[(\ta^b/d).*+?^$|]} - 3' | sed 's/'"$s"'/'"$r"'/g'

echo 'today is date.' | sed 's/date/'"$(date -I)"'/'

printf 'f1.txt\nf2.txt\n' | sed 's|^|'"$(pwd)"'/|'
Expand All @@ -36,5 +52,7 @@ p=$(pwd | sed 's|/|\\/|g')

printf 'f1.txt\nf2.txt\n' | sed 's/^/'"${p}"'\//'

echo '123' | sed 's/2/'"$(seq 5)"'/'
printf 'a\n[x]\nb\n' | sed 's/x/'"$(seq 3)"'/'

printf 'a\n[x]\nb\n' | sed 's/x/'"$(seq 3 | sed '$!s/$/\\/' )"'/'

2 changes: 1 addition & 1 deletion exercises/Exercises.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ $ echo 'a+42//5-c pressure*3+42/5-14256' | sed ##### add your solution here
a+8-c pressure*3+8-14256
```

**i)** For the given greedy quantifiers, what would be the equivalent form using `{m,n}` representation?
**i)** For the given quantifiers, what would be the equivalent form using `{m,n}` representation?

* `?` is same as
* `*` is same as
Expand Down
239 changes: 179 additions & 60 deletions gnu_sed.md

Large diffs are not rendered by default.

Binary file modified sample_chapters/sed_sample_chapters.pdf
Binary file not shown.

0 comments on commit 229a30a

Please sign in to comment.