-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58772a2
commit 0ae0525
Showing
38 changed files
with
100,506 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cat ip.txt | ||
|
||
cat fav_colors.txt | ||
|
||
sed '/red/r ip.txt' fav_colors.txt | ||
|
||
text='good\tone\nfood\tpun' | ||
|
||
echo "$text" | sed '1r /dev/stdin' ip.txt | ||
|
||
seq 2 | sed '2r /dev/stdin' ip.txt | ||
|
||
printf '123' | sed '1r /dev/stdin' ip.txt | ||
|
||
items=' * blue\n * green\n' | ||
|
||
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/R ip.txt' fav_colors.txt | ||
|
||
seq 4 | sed 'R /dev/stdin' fav_colors.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
printf 'spared no one\npar\nspar\n' | sed -n '/^sp/p' | ||
|
||
printf 'spared no one\npar\nspar\n' | sed -n '/ar$/p' | ||
|
||
printf 'spared no one\npar\nspar\n' | sed 's/^par$/PAR/' | ||
|
||
printf 'spared no one\npar\nspar\n' | sed 's/^/* /' | ||
|
||
printf 'spared no one\npar\nspar\n' | sed '/ /! s/$/./' | ||
|
||
cat word_anchors.txt | ||
|
||
sed -n '/\bpar/p' word_anchors.txt | ||
|
||
sed -n '/par\b/p' word_anchors.txt | ||
|
||
sed -n 's/\bpar\b/***/p' word_anchors.txt | ||
|
||
sed -n '/\Bpar\B/p' word_anchors.txt | ||
|
||
sed -n '/\Bpar/p' word_anchors.txt | ||
|
||
sed -n '/par\B/p' word_anchors.txt | ||
|
||
echo 'copper' | sed 's/\b/:/g' | ||
|
||
echo 'copper' | sed 's/\B/:/g' | ||
|
||
sed -n '/two\|sub/p' word_anchors.txt | ||
|
||
sed -nE '/two|sub/p' word_anchors.txt | ||
|
||
echo 'cats dog bee parrot foxed' | sed -E 's/cat|dog|fox/--/g' | ||
|
||
sed -nE '/\bpar\b|s$/p' word_anchors.txt | ||
|
||
echo 'cats dog bee parrot foxed' | sed -E 's/bee|parrot|at/--/' | ||
|
||
echo 'cats dog bee parrot foxed' | sed -E 's/parrot|at|bee/--/' | ||
|
||
echo 'spared party parent' | sed -E 's/spa|spared/**/g' | ||
|
||
echo 'spared party parent' | sed -E 's/spared|spa/**/g' | ||
|
||
printf 'red\nreform\nread\narrest\n' | sed -nE '/reform|rest/p' | ||
|
||
printf 'red\nreform\nread\narrest\n' | sed -nE '/re(form|st)/p' | ||
|
||
printf 'sub par\nspare\npart time\n' | sed -nE '/\bpar\b|\bpart\b/p' | ||
|
||
printf 'sub par\nspare\npart time\n' | sed -nE '/\b(par|part)\b/p' | ||
|
||
printf 'sub par\nspare\npart time\n' | sed -nE '/\bpar(|t)\b/p' | ||
|
||
echo 'a^2 + b^2 - C*3' | sed -n '/b^2/p' | ||
|
||
echo '$a = $b + $c' | sed -n '/$b/p' | ||
|
||
echo '$a = $b + $c' | sed 's/\$//g' | ||
|
||
printf '(a/b) + c\n3 + (a/b) - c\n' | sed -n '/^(a\/b)/p' | ||
|
||
printf '(a/b) + c\n3 + (a/b) - c\n' | sed -nE '/^\(a\/b\)/p' | ||
|
||
echo '/home/learnbyexample/reports' | sed 's/\/home\/learnbyexample\//~\//' | ||
|
||
echo '/home/learnbyexample/reports' | sed 's#/home/learnbyexample/#~/#' | ||
|
||
echo 'a/b/c/d' | sed 'y/a\/d/1-4/' | ||
|
||
echo 'a/b/c/d' | sed 'y,a/d,1-4,' | ||
|
||
printf '/foo/bar/1\n/foo/baz/1\n' | ||
|
||
printf '/foo/bar/1\n/foo/baz/1\n' | sed -n '\;/foo/bar/;p' | ||
|
||
echo 'tac tin cot abc:tyz excited' | sed 's/c.t/-/g' | ||
|
||
printf '42\t35\n' | sed 's/.3.//' | ||
|
||
printf 'abc\nxyz\n' | sed 'N; s/c.x/ /' | ||
|
||
echo 'fed fold fe:d feeder' | sed -E 's/\bfe.?d\b/X/g' | ||
|
||
printf 'sub par\nspare\npart time\n' | sed -nE '/\bpart?\b/p' | ||
|
||
echo 'par part parrot parent' | sed -E 's/par(ro)?t/X/g' | ||
|
||
echo 'par part parrot parent' | sed -E 's/par(en|ro)?t/X/g' | ||
|
||
echo 'blah \< foo bar < blah baz <' | sed -E 's/\\?</\\</g' | ||
|
||
echo 'fd fed fod fe:d feeeeder' | sed 's/fe*d/X/g' | ||
|
||
echo '3111111111125111142' | sed 's/1*2/-/g' | ||
|
||
echo 'fd fed fod fe:d feeeeder' | sed -E 's/fe+d/X/g' | ||
|
||
echo 'fd fed fod fe:d feeeeder' | sed -E 's/f(e|o|:)+d/X/g' | ||
|
||
echo '3111111111125111142' | sed -E 's/1+4?2/-/g' | ||
|
||
echo 'ac abc abbc abbbc abbbbbbbbc' | sed -E 's/ab{1,4}c/X/g' | ||
|
||
echo 'ac abc abbc abbbc abbbbbbbbc' | sed -E 's/ab{3,}c/X/g' | ||
|
||
echo 'ac abc abbc abbbc abbbbbbbbc' | sed -E 's/ab{,2}c/X/g' | ||
|
||
echo 'ac abc abbc abbbc abbbbbbbbc' | sed -E 's/ab{3}c/X/g' | ||
|
||
echo 'Error: not a valid input' | sed -n '/Error.*valid/p' | ||
|
||
echo 'two cats and a dog' | sed -E 's/cat.*dog|dog.*cat/pets/' | ||
|
||
echo 'two dogs and a cat' | sed -E 's/cat.*dog|dog.*cat/pets/' | ||
|
||
echo 'foot' | sed -E 's/f.?o/X/' | ||
|
||
echo 'car bat cod map scat dot abacus' | sed 's/.*/X/' | ||
|
||
echo 'car bat cod map scat dot abacus' | sed 's/.*m/-/' | ||
|
||
echo 'car bat cod map scat dot abacus' | sed 's/b.*t/-/' | ||
|
||
echo 'car bat cod map scat dot abacus' | sed 's/b.*at/-/' | ||
|
||
echo 'car bat cod map scat dot abacus' | sed 's/a.*m*/-/' | ||
|
||
printf 'cute\ncat\ncot\ncoat\ncost\nscuttle\n' | sed -n '/c[ou]t/p' | ||
|
||
printf 'meeting\ncute\nboat\nat\nfoot\n' | sed -nE '/.[aeo]+t/p' | ||
|
||
echo 'no so in to do on' | sed -E 's/\b[sot][on]\b/X/g' | ||
|
||
sed -nE '/^[on]{2,}$/p' words.txt | ||
|
||
echo 'Sample123string42with777numbers' | sed -E 's/[0-9]+/-/g' | ||
|
||
echo 'coat Bin food tar12 best' | sed -E 's/\b[a-z0-9]+\b/X/g' | ||
|
||
echo 'road i post grip read eat pit' | sed -E 's/\b[p-z][a-z]*\b/X/g' | ||
|
||
echo '23 154 12 26 34' | sed -E 's/\b[12][0-9]\b/X/g' | ||
|
||
echo '0501 035 154 12 26 98234' | sed -E 's/\b0*[1-9][0-9]{2,}\b/X/g' | ||
|
||
echo 'Sample123string42with777numbers' | sed -E 's/[^0-9]+/-/g' | ||
|
||
echo 'foo:123:bar:baz' | sed -E 's/(:[^:]+){2}$//' | ||
|
||
echo 'I like "mango" and "guava"' | sed -E 's/"[^"]+"/X/g' | ||
|
||
printf 'tryst\nfun\nglyph\npity\nwhy\n' | sed '/[aeiou]/d' | ||
|
||
echo 'load;err_msg--\nant,r2..not' | sed -E 's/\W+/-/g' | ||
|
||
printf 'hi \v\f there.\thave \ra nice\t\tday\n' | sed -E 's/\s+/ /g' | ||
|
||
echo 'w=y\x+9*3' | sed 's/[\w=]//g' | ||
|
||
echo 'err_msg xerox ant m_2 P2 load1 eel' | sed -E 's/\b[[:lower:]]+\b/X/g' | ||
|
||
echo 'err_msg xerox ant m_2 P2 load1 eel' | sed -E 's/\b[[:lower:]_]+\b/X/g' | ||
|
||
echo 'err_msg xerox ant m_2 P2 load1 eel' | sed -E 's/\b[[:alnum:]]+\b/X/g' | ||
|
||
echo ',pie tie#ink-eat_42' | sed -E 's/[^[:punct:]]+//g' | ||
|
||
echo 'ab-cd gh-c 12-423' | sed -E 's/[a-z-]{2,}/X/g' | ||
|
||
printf 'int a[5]\nfoo\n1+1=2\n' | sed -n '/[=]]/p' | ||
|
||
printf 'int a[5]\nfoo\n1+1=2\n' | sed -n '/[]=]/p' | ||
|
||
echo 'int a[5]' | sed -n '/[x[.y]/p' | ||
|
||
echo 'int a[5]' | sed -n '/[x[y.]/p' | ||
|
||
echo 'f*(a^b) - 3*(a+b)/(a-b)' | sed 's/a[+^]b/c/g' | ||
|
||
printf 'foo\tbar\tbaz\n' | sed 's/\t/ /g' | ||
|
||
echo 'a b c' | sed 's/ /\t/g' | ||
|
||
printf 'a\t\r\fb\vc\n' | sed -E 's/[\t\v\f\r]+/:/g' | ||
|
||
echo "universe: '42'" | sed 's/\x27/"/g' | ||
|
||
echo 'universe: "42"' | sed 's/"/\x27/g' | ||
|
||
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' | ||
|
||
echo 'aa a a a 42 f_1 f_1 f_13.14' | sed -E 's/\b(\w+)( \1)+\b/\1/g' | ||
|
||
sed -nE '/^([a-z]{3})..\1$/p' words.txt | ||
|
||
echo 'one,2,3.14,42' | sed -E 's/^([^,]+).*/&,\1/' | ||
|
||
echo 'hello world' | sed 's/.*/"&"/' | ||
|
||
echo 'hello world' | sed 's/.*/Hi. &. Have a nice day/' | ||
|
||
echo 'one,2,3.14,42' | sed -E 's/^(([^,]+,){2})([^,]+)/\1"\3"/' | ||
|
||
sed -nE '/^(\w*(\w)\2\w*){2}$/p' words.txt | head -n5 | ||
|
||
sed -nE '/^\w*(\w)\1\w*(\w)\2\w*$/p' words.txt | head -n5 | ||
|
||
echo 'foo and bar' | sed 's/and/[&]/' | ||
|
||
echo 'foo and bar' | sed 's/and/[\&]/' | ||
|
||
echo 'foo and bar' | sed 's/and/\\/' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cat nums.txt | ||
|
||
sed '/^-/{s///; b}; s/^/-/' nums.txt | ||
|
||
sed '/^-/ s///; t; s/^/-/' nums.txt | ||
|
||
echo '12345 hello42' | sed -E ':a s/^(\**)[0-9]/\1*/; ta' | ||
|
||
echo '123x45 hello42' | sed -E ':a s/^(\**)[0-9]/\1*/; ta' | ||
|
||
echo 'hi 12345 hello42' | sed -E ':a s/^(\**)[0-9]/\1*/; ta' | ||
|
||
echo 'he be me,1 2 3 4,nice slice' | sed -E ':b s/^([^,]*,[^ ,]*) /\1_/; tb' | ||
|
||
echo '1,,,two,,3' | sed 's/,,/,NA,/g' | ||
|
||
echo '1,,,two,,3' | sed -E ':c s/,,/,NA,/g; tc' | ||
|
||
echo 'coffining' | sed 's/fin//' | ||
|
||
echo 'coffining' | sed 's/fin//; s///' | ||
|
||
echo 'coffining' | sed ':d s/fin//; td' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
printf 'Cat\ncOnCaT\nscatter\ncot\n' | sed -n '/cat/p' | ||
|
||
printf 'Cat\ncOnCaT\nscatter\ncot\n' | sed -n '/cat/Ip' | ||
|
||
printf 'Cat\ncOnCaT\nscatter\ncot\n' | sed 's/cat/dog/I' | ||
|
||
echo 'hello there. how are you?' | sed 's/\b\w/\u&/g' | ||
|
||
echo 'HELLO THERE. HOW ARE YOU?' | sed 's/\b\w/\l&/g' | ||
|
||
echo '_foo aug_price next_line' | sed -E 's/([a-z])_([a-z])/\1\u\2/g' | ||
|
||
echo 'HaVE a nICe dAy' | sed 's/.*/\L&/' | ||
|
||
echo 'HaVE a nICe dAy' | sed 's/.*/\U&/' | ||
|
||
echo '_foo aug_price next_line' | sed -E 's/([a-z]+)(_[a-z]+)/\U\1\E\2/g' | ||
|
||
echo 'HeLLo:bYe gOoD:beTTEr' | sed -E 's/([a-z]+)(:[a-z]+)/\L\1\U\2/Ig' | ||
|
||
echo 'HeLLo:bYe gOoD:beTTEr' | sed -E 's/[a-z]+/\L\u&/Ig' | ||
|
||
echo 'HeLLo:bYe gOoD:beTTEr' | sed -E 's/[a-z]+/\U\l&/Ig' | ||
|
||
printf '1,2,3,4\na,b,c,d\n' | sed 's/,/-/' | ||
|
||
printf '1,2,3,4\na,b,c,d\n' | sed 's/,/-/g' | ||
|
||
echo 'foo:123:bar:baz' | sed 's/:/-/' | ||
|
||
echo 'foo:123:bar:baz' | sed -E 's/[^:]+/"&"/' | ||
|
||
echo 'foo:123:bar:baz' | sed 's/:/-/2' | ||
|
||
echo 'foo:123:bar:baz' | sed -E 's/[^:]+/"&"/2' | ||
|
||
echo 'foo:123:bar:baz' | sed 's/:/-/3' | ||
|
||
echo 'foo:123:bar:baz' | sed -E 's/[^:]+/"&"/3' | ||
|
||
echo '456:foo:123:bar:789:baz' | sed -E 's/(.*):/\1[]/' | ||
|
||
echo '456:foo:123:bar:789:baz' | sed -E 's/(.*):(.*:)/\1[]\2/' | ||
|
||
echo '456:foo:123:bar:789:baz' | sed -E 's/(.*):((.*:){2})/\1[]\2/' | ||
|
||
echo '456:foo:123:bar:789:baz' | sed -E 's/:/[]/2g' | ||
|
||
echo '456:foo:123:bar:789:baz' | sed -E 's/:/[]/4g' | ||
|
||
echo '456:foo:123:bar:789:baz' | sed 's/:/[]/2; s/:/[]/2' | ||
|
||
echo '456:foo:123:bar:789:baz' | sed 's/:/[]/3; s/:/[]/2' | ||
|
||
echo '456:foo:123:bar:789:baz' | sed 's/:/[]/5; s/:/[]/3; s/:/[]/2' | ||
|
||
echo 'hi there. have a nice day' | sed -n 's/xyz/XYZ/p' | ||
|
||
echo 'hi there. have a nice day' | sed -n 's/\bh/H/pg' | ||
|
||
seq 20 | sed -n 's/3/three/w 3.txt' | ||
|
||
cat 3.txt | ||
|
||
printf '1,2,3,4\na,b,c,d\n' | sed 's/,/:/gw cols.txt' | ||
|
||
cat cols.txt | ||
|
||
seq 20 | sed -n -e 's/5/five/w 5.txt' -e 's/7/seven/w 7.txt' | ||
|
||
cat 5.txt | ||
|
||
cat 7.txt | ||
|
||
sed -i 's/three/3/w /dev/stdout' 3.txt | ||
|
||
cat 3.txt | ||
|
||
printf 'Date:\nreplace this line\n' | ||
|
||
printf 'Date:\nreplace this line\n' | sed 's/^replace.*/date/e' | ||
|
||
printf 'Date:\nreplace this line\n' | sed -n 's/^replace.*/date/ep' | ||
|
||
printf 'Date:\nreplace this line\n' | sed -n 's/^replace.*/date/pe' | ||
|
||
echo 'xyz 5' | sed 's/xyz/seq/e' | ||
|
||
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 'Hi there\nHave a Nice Day\n' | sed 'N; s/H.*e/X/' | ||
|
||
printf 'Hi there\nHave a Nice Day\n' | sed 'N; s/H.*e/X/gm' | ||
|
||
printf 'Hi there\nHave a Nice Day\n' | sed 'N; s/^/* /g' | ||
|
||
printf 'Hi there\nHave a Nice Day\n' | sed 'N; s/$/./g' | ||
|
||
printf 'Hi there\nHave a Nice Day\n' | sed 'N; s/^/* /gm' | ||
|
||
printf 'Hi there\nHave a Nice Day\n' | sed 'N; s/$/./gm' | ||
|
||
printf 'Hi there\nHave a Nice Day\n' | sed 'N; s/\`/* /gm' | ||
|
||
printf 'Hi there\nHave a Nice Day\n' | sed "N; s/\'/./gm" | ||
|
||
printf 'Hi there\nHave a Nice Day\n' | sed -E 'N; s/H(\s|\S)*e/X/m' | ||
|
||
printf 'Hi there\nHave a Nice Day\n' | sed -E 'N; s/H(.*\n.*)*e/X/m' | ||
|
Oops, something went wrong.