├── cover_awk.png ├── cover_bash.png ├── cover_make.png ├── cover_sed.png ├── cover_macro.png ├── images ├── group.png ├── ml_1.png ├── ml_2.png ├── ml_3.png ├── ml_4.png ├── ml_44.png ├── ml_5.png ├── ml_6.png ├── basics_1.png ├── basics_2.png ├── commands.png ├── delete_1.png ├── delete_2.png ├── exchange.png ├── hold_1_1.png ├── hold_1_2.png ├── hold_2_1.png ├── hold_2_2.png ├── ml_1_1.png ├── ml_addr.png ├── ml_chars.png ├── next_1.png ├── next_2.png ├── print_1.png ├── print_2.png ├── subs_1.png ├── address_1.png ├── address_2.png ├── buttons │ ├── =.png │ ├── D.png │ ├── G.png │ ├── H.png │ ├── N.png │ ├── P.png │ ├── Q.png │ ├── R.png │ ├── T.png │ ├── W.png │ ├── a.png │ ├── b.png │ ├── c.png │ ├── d.png │ ├── e.png │ ├── g.png │ ├── h.png │ ├── i.png │ ├── l.png │ ├── n.png │ ├── p.png │ ├── q.png │ ├── r.png │ ├── s.png │ ├── t.png │ ├── w.png │ ├── x.png │ ├── y.png │ └── z.png ├── execute_1.png ├── ml_delete1.png ├── ml_delete2.png ├── ml_delete3.png ├── pattern_1.png ├── pattern_2.png ├── print_1_1.png ├── file_editing.mp4 └── move_example.png ├── gitbook ├── images │ ├── favicon.ico │ └── apple-touch-icon-precomposed-152.png ├── fonts │ └── fontawesome │ │ ├── FontAwesome.otf │ │ ├── fontawesome-webfont.eot │ │ ├── fontawesome-webfont.ttf │ │ └── fontawesome-webfont.woff └── plugins │ ├── gitbook-plugin-search │ ├── search.css │ ├── search.js │ └── lunr.min.js │ ├── gitbook-plugin-sharing │ └── buttons.js │ ├── gitbook-plugin-highlight │ └── ebook.css │ └── gitbook-plugin-fontsettings │ ├── buttons.js │ └── website.css ├── styles └── website.css ├── closing.md ├── commands.html ├── escape_sequences.html ├── index.html ├── bug_reports.html ├── print.html ├── debugging.html ├── delete.html └── and_or_not.html /cover_awk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/cover_awk.png -------------------------------------------------------------------------------- /cover_bash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/cover_bash.png -------------------------------------------------------------------------------- /cover_make.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/cover_make.png -------------------------------------------------------------------------------- /cover_sed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/cover_sed.png -------------------------------------------------------------------------------- /cover_macro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/cover_macro.png -------------------------------------------------------------------------------- /images/group.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/group.png -------------------------------------------------------------------------------- /images/ml_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/ml_1.png -------------------------------------------------------------------------------- /images/ml_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/ml_2.png -------------------------------------------------------------------------------- /images/ml_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/ml_3.png -------------------------------------------------------------------------------- /images/ml_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/ml_4.png -------------------------------------------------------------------------------- /images/ml_44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/ml_44.png -------------------------------------------------------------------------------- /images/ml_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/ml_5.png -------------------------------------------------------------------------------- /images/ml_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/ml_6.png -------------------------------------------------------------------------------- /images/basics_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/basics_1.png -------------------------------------------------------------------------------- /images/basics_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/basics_2.png -------------------------------------------------------------------------------- /images/commands.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/commands.png -------------------------------------------------------------------------------- /images/delete_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/delete_1.png -------------------------------------------------------------------------------- /images/delete_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/delete_2.png -------------------------------------------------------------------------------- /images/exchange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/exchange.png -------------------------------------------------------------------------------- /images/hold_1_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/hold_1_1.png -------------------------------------------------------------------------------- /images/hold_1_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/hold_1_2.png -------------------------------------------------------------------------------- /images/hold_2_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/hold_2_1.png -------------------------------------------------------------------------------- /images/hold_2_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/hold_2_2.png -------------------------------------------------------------------------------- /images/ml_1_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/ml_1_1.png -------------------------------------------------------------------------------- /images/ml_addr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/ml_addr.png -------------------------------------------------------------------------------- /images/ml_chars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/ml_chars.png -------------------------------------------------------------------------------- /images/next_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/next_1.png -------------------------------------------------------------------------------- /images/next_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/next_2.png -------------------------------------------------------------------------------- /images/print_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/print_1.png -------------------------------------------------------------------------------- /images/print_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/print_2.png -------------------------------------------------------------------------------- /images/subs_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/subs_1.png -------------------------------------------------------------------------------- /images/address_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/address_1.png -------------------------------------------------------------------------------- /images/address_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/address_2.png -------------------------------------------------------------------------------- /images/buttons/=.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/=.png -------------------------------------------------------------------------------- /images/buttons/D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/D.png -------------------------------------------------------------------------------- /images/buttons/G.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/G.png -------------------------------------------------------------------------------- /images/buttons/H.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/H.png -------------------------------------------------------------------------------- /images/buttons/N.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/N.png -------------------------------------------------------------------------------- /images/buttons/P.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/P.png -------------------------------------------------------------------------------- /images/buttons/Q.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/Q.png -------------------------------------------------------------------------------- /images/buttons/R.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/R.png -------------------------------------------------------------------------------- /images/buttons/T.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/T.png -------------------------------------------------------------------------------- /images/buttons/W.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/W.png -------------------------------------------------------------------------------- /images/buttons/a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/a.png -------------------------------------------------------------------------------- /images/buttons/b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/b.png -------------------------------------------------------------------------------- /images/buttons/c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/c.png -------------------------------------------------------------------------------- /images/buttons/d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/d.png -------------------------------------------------------------------------------- /images/buttons/e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/e.png -------------------------------------------------------------------------------- /images/buttons/g.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/g.png -------------------------------------------------------------------------------- /images/buttons/h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/h.png -------------------------------------------------------------------------------- /images/buttons/i.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/i.png -------------------------------------------------------------------------------- /images/buttons/l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/l.png -------------------------------------------------------------------------------- /images/buttons/n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/n.png -------------------------------------------------------------------------------- /images/buttons/p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/p.png -------------------------------------------------------------------------------- /images/buttons/q.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/q.png -------------------------------------------------------------------------------- /images/buttons/r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/r.png -------------------------------------------------------------------------------- /images/buttons/s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/s.png -------------------------------------------------------------------------------- /images/buttons/t.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/t.png -------------------------------------------------------------------------------- /images/buttons/w.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/w.png -------------------------------------------------------------------------------- /images/buttons/x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/x.png -------------------------------------------------------------------------------- /images/buttons/y.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/y.png -------------------------------------------------------------------------------- /images/buttons/z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/buttons/z.png -------------------------------------------------------------------------------- /images/execute_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/execute_1.png -------------------------------------------------------------------------------- /images/ml_delete1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/ml_delete1.png -------------------------------------------------------------------------------- /images/ml_delete2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/ml_delete2.png -------------------------------------------------------------------------------- /images/ml_delete3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/ml_delete3.png -------------------------------------------------------------------------------- /images/pattern_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/pattern_1.png -------------------------------------------------------------------------------- /images/pattern_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/pattern_2.png -------------------------------------------------------------------------------- /images/print_1_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/print_1_1.png -------------------------------------------------------------------------------- /images/file_editing.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/file_editing.mp4 -------------------------------------------------------------------------------- /images/move_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/images/move_example.png -------------------------------------------------------------------------------- /gitbook/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/gitbook/images/favicon.ico -------------------------------------------------------------------------------- /gitbook/fonts/fontawesome/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/gitbook/fonts/fontawesome/FontAwesome.otf -------------------------------------------------------------------------------- /gitbook/fonts/fontawesome/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/gitbook/fonts/fontawesome/fontawesome-webfont.eot -------------------------------------------------------------------------------- /gitbook/fonts/fontawesome/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/gitbook/fonts/fontawesome/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /gitbook/fonts/fontawesome/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/gitbook/fonts/fontawesome/fontawesome-webfont.woff -------------------------------------------------------------------------------- /gitbook/images/apple-touch-icon-precomposed-152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mug896/sed-stream-editor/HEAD/gitbook/images/apple-touch-icon-precomposed-152.png -------------------------------------------------------------------------------- /styles/website.css: -------------------------------------------------------------------------------- 1 | .m_button_fl { float: left } 2 | .m_button_fr { float: right } 3 | .m_button_ml { margin-left: 5px } 4 | .m_button_mr { margin-right: 5px } 5 | -------------------------------------------------------------------------------- /gitbook/plugins/gitbook-plugin-search/search.css: -------------------------------------------------------------------------------- 1 | .book .book-summary .book-search { 2 | padding: 6px; 3 | background: transparent; 4 | position: absolute; 5 | top: -50px; 6 | left: 0px; 7 | right: 0px; 8 | transition: top 0.5s ease; 9 | } 10 | .book .book-summary .book-search input, 11 | .book .book-summary .book-search input:focus, 12 | .book .book-summary .book-search input:hover { 13 | width: 100%; 14 | background: transparent; 15 | border: 1px solid transparent; 16 | box-shadow: none; 17 | outline: none; 18 | line-height: 22px; 19 | padding: 7px 4px; 20 | color: inherit; 21 | } 22 | .book.with-search .book-summary .book-search { 23 | top: 0px; 24 | } 25 | .book.with-search .book-summary ul.summary { 26 | top: 50px; 27 | } 28 | -------------------------------------------------------------------------------- /closing.md: -------------------------------------------------------------------------------- 1 | # 맺음말 2 | 3 | 4 | sed 는 필요에 따라 사용할 수 있는 함수를 제공하지 않기 때문에 모든 문제를 regex 과 몇 개의 sed 명령을 이용해서 해결해야 합니다. 5 | 그래서 처음 sed 를 사용할 때는 어떻게 처리해야 될지 방법이 잘 떠오르지 않는 경우가 많은데요. 6 | 명령이 몇 개 안되고 구조가 간단하다고 해서 사용방법까지 간단하지 않은 걸 알 수 있습니다. 7 | 8 | 함수가 많다는 것은 다시 말하면 문제를 쉽게 해결할 수 있는 방법이 많다고도 할 수 있습니다. 9 | 함수가 정형화된 기법이라면 sed 는 함수를 제공하지 않기 때문에 몇가지 자주 사용되는 기법들을 알고 있어야 하는데요. 10 | 그러기 위해서는 실제로 문제를 여러개 풀어보는 것이 좋습니다. 11 | stackoverflow.com 나 unix.stackexchange.com 같은 Q&A 사이트에서 12 | sed 태그로 검색을 해보면 관련된 질문과 답변들을 볼수 있는데 정말 생각지도 못한 방법으로 문제를 해결하는 분들이 있습니다. 13 | 14 | 시간을 내어서 문제를 풀다 보면 "sed 로 처리할 수 있는게 몇 개 안돼.." 에서 "대부분 sed 로 처리가 가능하네.." 15 | 로 바뀌게 될 것이라고 생각합니다. 16 | 17 | 18 | > sed 버전이 4.2.2 에서 4년 만에 4.4 로 업데이트 되었습니다. 19 | > regex 매칭 속도가 10배 빨라졌다고 하는데요. 현재 대부분의 시스템에는 4.2.2 버전이 설치되어 있을 텐데 20 | > https://packages.debian.org/sid/amd64/sed/download 에서 deb 패키지를 다운로드하실 수 있습니다. 21 | -------------------------------------------------------------------------------- /gitbook/plugins/gitbook-plugin-sharing/buttons.js: -------------------------------------------------------------------------------- 1 | require(["gitbook", "lodash"], function(gitbook, _) { 2 | var SITES = { 3 | 'facebook': { 4 | 'label': 'Facebook', 5 | 'icon': 'fa fa-facebook', 6 | 'onClick': function(e) { 7 | e.preventDefault(); 8 | window.open("http://www.facebook.com/sharer/sharer.php?s=100&p[url]="+encodeURIComponent(location.href)); 9 | } 10 | }, 11 | 'twitter': { 12 | 'label': 'Twitter', 13 | 'icon': 'fa fa-twitter', 14 | 'onClick': function(e) { 15 | e.preventDefault(); 16 | window.open("http://twitter.com/home?status="+encodeURIComponent(document.title+" "+location.href)); 17 | } 18 | }, 19 | 'google': { 20 | 'label': 'Google+', 21 | 'icon': 'fa fa-google-plus', 22 | 'onClick': function(e) { 23 | e.preventDefault(); 24 | window.open("https://plus.google.com/share?url="+encodeURIComponent(location.href)); 25 | } 26 | }, 27 | 'weibo': { 28 | 'label': 'Weibo', 29 | 'icon': 'fa fa-weibo', 30 | 'onClick': function(e) { 31 | e.preventDefault(); 32 | window.open("http://service.weibo.com/share/share.php?content=utf-8&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title)); 33 | } 34 | }, 35 | 'instapaper': { 36 | 'label': 'Instapaper', 37 | 'icon': 'fa fa-instapaper', 38 | 'onClick': function(e) { 39 | e.preventDefault(); 40 | window.open("http://www.instapaper.com/text?u="+encodeURIComponent(location.href)); 41 | } 42 | }, 43 | 'vk': { 44 | 'label': 'VK', 45 | 'icon': 'fa fa-vk', 46 | 'onClick': function(e) { 47 | e.preventDefault(); 48 | window.open("http://vkontakte.ru/share.php?url="+encodeURIComponent(location.href)); 49 | } 50 | } 51 | }; 52 | 53 | 54 | 55 | gitbook.events.bind("start", function(e, config) { 56 | var opts = config.sharing; 57 | 58 | // Create dropdown menu 59 | var menu = _.chain(opts.all) 60 | .map(function(id) { 61 | var site = SITES[id]; 62 | 63 | return { 64 | text: site.label, 65 | onClick: site.onClick 66 | }; 67 | }) 68 | .compact() 69 | .value(); 70 | 71 | // Create main button with dropdown 72 | if (menu.length > 0) { 73 | gitbook.toolbar.createButton({ 74 | icon: 'fa fa-share-alt', 75 | label: 'Share', 76 | position: 'right', 77 | dropdown: [menu] 78 | }); 79 | } 80 | 81 | // Direct actions to share 82 | _.each(SITES, function(site, sideId) { 83 | if (!opts[sideId]) return; 84 | 85 | gitbook.toolbar.createButton({ 86 | icon: site.icon, 87 | label: site.text, 88 | position: 'right', 89 | onClick: site.onClick 90 | }); 91 | }); 92 | }); 93 | }); 94 | -------------------------------------------------------------------------------- /gitbook/plugins/gitbook-plugin-highlight/ebook.css: -------------------------------------------------------------------------------- 1 | pre, 2 | code { 3 | /* http://jmblog.github.io/color-themes-for-highlightjs */ 4 | /* Tomorrow Comment */ 5 | /* Tomorrow Red */ 6 | /* Tomorrow Orange */ 7 | /* Tomorrow Yellow */ 8 | /* Tomorrow Green */ 9 | /* Tomorrow Aqua */ 10 | /* Tomorrow Blue */ 11 | /* Tomorrow Purple */ 12 | } 13 | pre .hljs-comment, 14 | code .hljs-comment, 15 | pre .hljs-title, 16 | code .hljs-title { 17 | color: #8e908c; 18 | } 19 | pre .hljs-variable, 20 | code .hljs-variable, 21 | pre .hljs-attribute, 22 | code .hljs-attribute, 23 | pre .hljs-tag, 24 | code .hljs-tag, 25 | pre .hljs-regexp, 26 | code .hljs-regexp, 27 | pre .ruby .hljs-constant, 28 | code .ruby .hljs-constant, 29 | pre .xml .hljs-tag .hljs-title, 30 | code .xml .hljs-tag .hljs-title, 31 | pre .xml .hljs-pi, 32 | code .xml .hljs-pi, 33 | pre .xml .hljs-doctype, 34 | code .xml .hljs-doctype, 35 | pre .html .hljs-doctype, 36 | code .html .hljs-doctype, 37 | pre .css .hljs-id, 38 | code .css .hljs-id, 39 | pre .css .hljs-class, 40 | code .css .hljs-class, 41 | pre .css .hljs-pseudo, 42 | code .css .hljs-pseudo { 43 | color: #c82829; 44 | } 45 | pre .hljs-number, 46 | code .hljs-number, 47 | pre .hljs-preprocessor, 48 | code .hljs-preprocessor, 49 | pre .hljs-pragma, 50 | code .hljs-pragma, 51 | pre .hljs-built_in, 52 | code .hljs-built_in, 53 | pre .hljs-literal, 54 | code .hljs-literal, 55 | pre .hljs-params, 56 | code .hljs-params, 57 | pre .hljs-constant, 58 | code .hljs-constant { 59 | color: #f5871f; 60 | } 61 | pre .ruby .hljs-class .hljs-title, 62 | code .ruby .hljs-class .hljs-title, 63 | pre .css .hljs-rules .hljs-attribute, 64 | code .css .hljs-rules .hljs-attribute { 65 | color: #eab700; 66 | } 67 | pre .hljs-string, 68 | code .hljs-string, 69 | pre .hljs-value, 70 | code .hljs-value, 71 | pre .hljs-inheritance, 72 | code .hljs-inheritance, 73 | pre .hljs-header, 74 | code .hljs-header, 75 | pre .ruby .hljs-symbol, 76 | code .ruby .hljs-symbol, 77 | pre .xml .hljs-cdata, 78 | code .xml .hljs-cdata { 79 | color: #718c00; 80 | } 81 | pre .css .hljs-hexcolor, 82 | code .css .hljs-hexcolor { 83 | color: #3e999f; 84 | } 85 | pre .hljs-function, 86 | code .hljs-function, 87 | pre .python .hljs-decorator, 88 | code .python .hljs-decorator, 89 | pre .python .hljs-title, 90 | code .python .hljs-title, 91 | pre .ruby .hljs-function .hljs-title, 92 | code .ruby .hljs-function .hljs-title, 93 | pre .ruby .hljs-title .hljs-keyword, 94 | code .ruby .hljs-title .hljs-keyword, 95 | pre .perl .hljs-sub, 96 | code .perl .hljs-sub, 97 | pre .javascript .hljs-title, 98 | code .javascript .hljs-title, 99 | pre .coffeescript .hljs-title, 100 | code .coffeescript .hljs-title { 101 | color: #4271ae; 102 | } 103 | pre .hljs-keyword, 104 | code .hljs-keyword, 105 | pre .javascript .hljs-function, 106 | code .javascript .hljs-function { 107 | color: #8959a8; 108 | } 109 | pre .hljs, 110 | code .hljs { 111 | display: block; 112 | background: white; 113 | color: #4d4d4c; 114 | padding: 0.5em; 115 | } 116 | pre .coffeescript .javascript, 117 | code .coffeescript .javascript, 118 | pre .javascript .xml, 119 | code .javascript .xml, 120 | pre .tex .hljs-formula, 121 | code .tex .hljs-formula, 122 | pre .xml .javascript, 123 | code .xml .javascript, 124 | pre .xml .vbscript, 125 | code .xml .vbscript, 126 | pre .xml .css, 127 | code .xml .css, 128 | pre .xml .hljs-cdata, 129 | code .xml .hljs-cdata { 130 | opacity: 0.5; 131 | } 132 | -------------------------------------------------------------------------------- /gitbook/plugins/gitbook-plugin-search/search.js: -------------------------------------------------------------------------------- 1 | require([ 2 | "gitbook", 3 | "lodash" 4 | ], function(gitbook, _) { 5 | var index = null; 6 | var $searchInput, $searchForm; 7 | 8 | // Use a specific index 9 | function loadIndex(data) { 10 | index = lunr.Index.load(data); 11 | } 12 | 13 | // Fetch the search index 14 | function fetchIndex() { 15 | $.getJSON(gitbook.state.basePath+"/search_index.json") 16 | .then(loadIndex); 17 | } 18 | 19 | // Search for a term and return results 20 | function search(q) { 21 | if (!index) return; 22 | 23 | var results = _.chain(index.search(q)) 24 | .map(function(result) { 25 | var parts = result.ref.split("#") 26 | return { 27 | path: parts[0], 28 | hash: parts[1] 29 | } 30 | }) 31 | .value(); 32 | 33 | return results; 34 | } 35 | 36 | // Create search form 37 | function createForm(value) { 38 | if ($searchForm) $searchForm.remove(); 39 | 40 | $searchForm = $('
', { 41 | 'class': 'book-search', 42 | 'role': 'search' 43 | }); 44 | 45 | $searchInput = $('', { 46 | 'type': 'text', 47 | 'class': 'form-control', 48 | 'val': value, 49 | 'placeholder': 'Type to search' 50 | }); 51 | 52 | $searchInput.appendTo($searchForm); 53 | $searchForm.prependTo(gitbook.state.$book.find('.book-summary')); 54 | } 55 | 56 | // Return true if search is open 57 | function isSearchOpen() { 58 | return gitbook.state.$book.hasClass("with-search"); 59 | } 60 | 61 | // Toggle the search 62 | function toggleSearch(_state) { 63 | if (isSearchOpen() === _state) return; 64 | 65 | gitbook.state.$book.toggleClass("with-search", _state); 66 | 67 | // If search bar is open: focus input 68 | if (isSearchOpen()) { 69 | gitbook.sidebar.toggle(true); 70 | $searchInput.focus(); 71 | } else { 72 | $searchInput.blur(); 73 | $searchInput.val(""); 74 | gitbook.sidebar.filter(null); 75 | } 76 | } 77 | 78 | // Recover current search when page changed 79 | function recoverSearch() { 80 | var keyword = gitbook.storage.get("keyword", ""); 81 | 82 | createForm(keyword); 83 | 84 | if (keyword.length > 0) { 85 | if(!isSearchOpen()) { 86 | toggleSearch(); 87 | } 88 | gitbook.sidebar.filter(_.pluck(search(keyword), "path")); 89 | } 90 | }; 91 | 92 | 93 | gitbook.events.bind("start", function(config) { 94 | // Pre-fetch search index and create the form 95 | fetchIndex(); 96 | createForm(); 97 | 98 | // Type in search bar 99 | $(document).on("keyup", ".book-search input", function(e) { 100 | var key = (e.keyCode ? e.keyCode : e.which); 101 | var q = $(this).val(); 102 | 103 | if (key == 27) { 104 | e.preventDefault(); 105 | toggleSearch(false); 106 | return; 107 | } 108 | if (q.length == 0) { 109 | gitbook.sidebar.filter(null); 110 | gitbook.storage.remove("keyword"); 111 | } else { 112 | var results = search(q); 113 | gitbook.sidebar.filter( 114 | _.pluck(results, "path") 115 | ); 116 | gitbook.storage.set("keyword", q); 117 | } 118 | }); 119 | 120 | // Create the toggle search button 121 | gitbook.toolbar.createButton({ 122 | icon: 'fa fa-search', 123 | label: 'Search', 124 | position: 'left', 125 | onClick: toggleSearch 126 | }); 127 | 128 | // Bind keyboard to toggle search 129 | gitbook.keyboard.bind(['f'], toggleSearch) 130 | }); 131 | 132 | gitbook.events.bind("page.change", recoverSearch); 133 | }); 134 | 135 | 136 | -------------------------------------------------------------------------------- /gitbook/plugins/gitbook-plugin-fontsettings/buttons.js: -------------------------------------------------------------------------------- 1 | require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) { 2 | var fontState; 3 | 4 | var THEMES = { 5 | "white": 0, 6 | "sepia": 1, 7 | "night": 2 8 | }; 9 | 10 | var FAMILY = { 11 | "serif": 0, 12 | "sans": 1 13 | }; 14 | 15 | // Save current font settings 16 | function saveFontSettings() { 17 | gitbook.storage.set("fontState", fontState); 18 | update(); 19 | } 20 | 21 | // Increase font size 22 | function enlargeFontSize(e) { 23 | e.preventDefault(); 24 | if (fontState.size >= 4) return; 25 | 26 | fontState.size++; 27 | saveFontSettings(); 28 | }; 29 | 30 | // Decrease font size 31 | function reduceFontSize(e) { 32 | e.preventDefault(); 33 | if (fontState.size <= 0) return; 34 | 35 | fontState.size--; 36 | saveFontSettings(); 37 | }; 38 | 39 | // Change font family 40 | function changeFontFamily(index, e) { 41 | e.preventDefault(); 42 | 43 | fontState.family = index; 44 | saveFontSettings(); 45 | }; 46 | 47 | // Change type of color 48 | function changeColorTheme(index, e) { 49 | e.preventDefault(); 50 | 51 | var $book = $(".book"); 52 | 53 | if (fontState.theme !== 0) 54 | $book.removeClass("color-theme-"+fontState.theme); 55 | 56 | fontState.theme = index; 57 | if (fontState.theme !== 0) 58 | $book.addClass("color-theme-"+fontState.theme); 59 | 60 | saveFontSettings(); 61 | }; 62 | 63 | function update() { 64 | var $book = gitbook.state.$book; 65 | 66 | $(".font-settings .font-family-list li").removeClass("active"); 67 | $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active"); 68 | 69 | $book[0].className = $book[0].className.replace(/\bfont-\S+/g, ''); 70 | $book.addClass("font-size-"+fontState.size); 71 | $book.addClass("font-family-"+fontState.family); 72 | 73 | if(fontState.theme !== 0) { 74 | $book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, ''); 75 | $book.addClass("color-theme-"+fontState.theme); 76 | } 77 | }; 78 | 79 | function init(config) { 80 | var $bookBody, $book; 81 | 82 | //Find DOM elements. 83 | $book = gitbook.state.$book; 84 | $bookBody = $book.find(".book-body"); 85 | 86 | // Instantiate font state object 87 | fontState = gitbook.storage.get("fontState", { 88 | size: config.size || 2, 89 | family: FAMILY[config.family || "sans"], 90 | theme: THEMES[config.theme || "white"] 91 | }); 92 | 93 | update(); 94 | }; 95 | 96 | 97 | gitbook.events.bind("start", function(e, config) { 98 | var opts = config.fontsettings; 99 | 100 | // Create buttons in toolbar 101 | gitbook.toolbar.createButton({ 102 | icon: 'fa fa-font', 103 | label: 'Font Settings', 104 | className: 'font-settings', 105 | dropdown: [ 106 | [ 107 | { 108 | text: 'A', 109 | className: 'font-reduce', 110 | onClick: reduceFontSize 111 | }, 112 | { 113 | text: 'A', 114 | className: 'font-enlarge', 115 | onClick: enlargeFontSize 116 | } 117 | ], 118 | [ 119 | { 120 | text: 'Serif', 121 | onClick: _.partial(changeFontFamily, 0) 122 | }, 123 | { 124 | text: 'Sans', 125 | onClick: _.partial(changeFontFamily, 1) 126 | } 127 | ], 128 | [ 129 | { 130 | text: 'White', 131 | onClick: _.partial(changeColorTheme, 0) 132 | }, 133 | { 134 | text: 'Sepia', 135 | onClick: _.partial(changeColorTheme, 1) 136 | }, 137 | { 138 | text: 'Night', 139 | onClick: _.partial(changeColorTheme, 2) 140 | } 141 | ] 142 | ] 143 | }); 144 | 145 | 146 | // Init current settings 147 | init(opts); 148 | }); 149 | }); 150 | 151 | 152 | -------------------------------------------------------------------------------- /gitbook/plugins/gitbook-plugin-fontsettings/website.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Theme 1 3 | */ 4 | .color-theme-1 .dropdown-menu { 5 | background-color: #111111; 6 | border-color: #7e888b; 7 | } 8 | .color-theme-1 .dropdown-menu .dropdown-caret .caret-inner { 9 | border-bottom: 9px solid #111111; 10 | } 11 | .color-theme-1 .dropdown-menu .buttons { 12 | border-color: #7e888b; 13 | } 14 | .color-theme-1 .dropdown-menu .button { 15 | color: #afa790; 16 | } 17 | .color-theme-1 .dropdown-menu .button:hover { 18 | color: #73553c; 19 | } 20 | /* 21 | * Theme 2 22 | */ 23 | .color-theme-2 .dropdown-menu { 24 | background-color: #2d3143; 25 | border-color: #272a3a; 26 | } 27 | .color-theme-2 .dropdown-menu .dropdown-caret .caret-inner { 28 | border-bottom: 9px solid #2d3143; 29 | } 30 | .color-theme-2 .dropdown-menu .buttons { 31 | border-color: #272a3a; 32 | } 33 | .color-theme-2 .dropdown-menu .button { 34 | color: #62677f; 35 | } 36 | .color-theme-2 .dropdown-menu .button:hover { 37 | color: #f4f4f5; 38 | } 39 | .book .book-header .font-settings .font-enlarge { 40 | line-height: 30px; 41 | font-size: 1.4em; 42 | } 43 | .book .book-header .font-settings .font-reduce { 44 | line-height: 30px; 45 | font-size: 1em; 46 | } 47 | .book.color-theme-1 .book-body { 48 | color: #704214; 49 | background: #f3eacb; 50 | } 51 | .book.color-theme-1 .book-body .page-wrapper .page-inner section { 52 | background: #f3eacb; 53 | } 54 | .book.color-theme-2 .book-body { 55 | color: #bdcadb; 56 | background: #1c1f2b; 57 | } 58 | .book.color-theme-2 .book-body .page-wrapper .page-inner section { 59 | background: #1c1f2b; 60 | } 61 | .book.font-size-0 .book-body .page-inner section { 62 | font-size: 1.2rem; 63 | } 64 | .book.font-size-1 .book-body .page-inner section { 65 | font-size: 1.4rem; 66 | } 67 | .book.font-size-2 .book-body .page-inner section { 68 | font-size: 1.6rem; 69 | } 70 | .book.font-size-3 .book-body .page-inner section { 71 | font-size: 2.2rem; 72 | } 73 | .book.font-size-4 .book-body .page-inner section { 74 | font-size: 4rem; 75 | } 76 | .book.font-family-0 { 77 | font-family: Georgia, serif; 78 | } 79 | .book.font-family-1 { 80 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 81 | } 82 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal { 83 | color: #704214; 84 | } 85 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal a { 86 | color: inherit; 87 | } 88 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h1, 89 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h2, 90 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h3, 91 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h4, 92 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h5, 93 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h6 { 94 | color: inherit; 95 | } 96 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h1, 97 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h2 { 98 | border-color: inherit; 99 | } 100 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h6 { 101 | color: inherit; 102 | } 103 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal hr { 104 | background-color: inherit; 105 | } 106 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal blockquote { 107 | border-color: inherit; 108 | } 109 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal pre, 110 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal code { 111 | background: #fdf6e3; 112 | color: #657b83; 113 | border-color: #f8df9c; 114 | } 115 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal .highlight { 116 | background-color: inherit; 117 | } 118 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table th, 119 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table td { 120 | border-color: #f5d06c; 121 | } 122 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table tr { 123 | color: inherit; 124 | background-color: #fdf6e3; 125 | border-color: #444444; 126 | } 127 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n) { 128 | background-color: #fbeecb; 129 | } 130 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal { 131 | color: #bdcadb; 132 | } 133 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal a { 134 | color: #3eb1d0; 135 | } 136 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h1, 137 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h2, 138 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h3, 139 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h4, 140 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h5, 141 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h6 { 142 | color: #fffffa; 143 | } 144 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h1, 145 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h2 { 146 | border-color: #373b4e; 147 | } 148 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h6 { 149 | color: #373b4e; 150 | } 151 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal hr { 152 | background-color: #373b4e; 153 | } 154 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal blockquote { 155 | border-color: #373b4e; 156 | } 157 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal pre, 158 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal code { 159 | color: #9dbed8; 160 | background: #2d3143; 161 | border-color: #2d3143; 162 | } 163 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal .highlight { 164 | background-color: #282a39; 165 | } 166 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table th, 167 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table td { 168 | border-color: #3b3f54; 169 | } 170 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table tr { 171 | color: #b6c2d2; 172 | background-color: #2d3143; 173 | border-color: #3b3f54; 174 | } 175 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n) { 176 | background-color: #35394b; 177 | } 178 | .book.color-theme-1 .book-header { 179 | color: #afa790; 180 | background: transparent; 181 | } 182 | .book.color-theme-1 .book-header .btn { 183 | color: #afa790; 184 | } 185 | .book.color-theme-1 .book-header .btn:hover { 186 | color: #73553c; 187 | background: none; 188 | } 189 | .book.color-theme-1 .book-header h1 { 190 | color: #704214; 191 | } 192 | .book.color-theme-2 .book-header { 193 | color: #7e888b; 194 | background: transparent; 195 | } 196 | .book.color-theme-2 .book-header .btn { 197 | color: #3b3f54; 198 | } 199 | .book.color-theme-2 .book-header .btn:hover { 200 | color: #fffff5; 201 | background: none; 202 | } 203 | .book.color-theme-2 .book-header h1 { 204 | color: #bdcadb; 205 | } 206 | .book.color-theme-1 .book-body .navigation { 207 | color: #afa790; 208 | } 209 | .book.color-theme-1 .book-body .navigation:hover { 210 | color: #73553c; 211 | } 212 | .book.color-theme-2 .book-body .navigation { 213 | color: #383f52; 214 | } 215 | .book.color-theme-2 .book-body .navigation:hover { 216 | color: #fffff5; 217 | } 218 | /* 219 | * Theme 1 220 | */ 221 | .book.color-theme-1 .book-summary { 222 | color: #afa790; 223 | background: #111111; 224 | border-right: 1px solid rgba(0, 0, 0, 0.07); 225 | } 226 | .book.color-theme-1 .book-summary .book-search { 227 | background: transparent; 228 | } 229 | .book.color-theme-1 .book-summary .book-search input, 230 | .book.color-theme-1 .book-summary .book-search input:focus { 231 | border: 1px solid transparent; 232 | } 233 | .book.color-theme-1 .book-summary ul.summary li.divider { 234 | background: #7e888b; 235 | box-shadow: none; 236 | } 237 | .book.color-theme-1 .book-summary ul.summary li i.fa-check { 238 | color: #33cc33; 239 | } 240 | .book.color-theme-1 .book-summary ul.summary li.done > a { 241 | color: #877f6a; 242 | } 243 | .book.color-theme-1 .book-summary ul.summary li a, 244 | .book.color-theme-1 .book-summary ul.summary li span { 245 | color: #877f6a; 246 | background: transparent; 247 | font-weight: normal; 248 | } 249 | .book.color-theme-1 .book-summary ul.summary li.active > a, 250 | .book.color-theme-1 .book-summary ul.summary li a:hover { 251 | color: #704214; 252 | background: transparent; 253 | font-weight: normal; 254 | } 255 | /* 256 | * Theme 2 257 | */ 258 | .book.color-theme-2 .book-summary { 259 | color: #bcc1d2; 260 | background: #2d3143; 261 | border-right: none; 262 | } 263 | .book.color-theme-2 .book-summary .book-search { 264 | background: transparent; 265 | } 266 | .book.color-theme-2 .book-summary .book-search input, 267 | .book.color-theme-2 .book-summary .book-search input:focus { 268 | border: 1px solid transparent; 269 | } 270 | .book.color-theme-2 .book-summary ul.summary li.divider { 271 | background: #272a3a; 272 | box-shadow: none; 273 | } 274 | .book.color-theme-2 .book-summary ul.summary li i.fa-check { 275 | color: #33cc33; 276 | } 277 | .book.color-theme-2 .book-summary ul.summary li.done > a { 278 | color: #62687f; 279 | } 280 | .book.color-theme-2 .book-summary ul.summary li a, 281 | .book.color-theme-2 .book-summary ul.summary li span { 282 | color: #c1c6d7; 283 | background: transparent; 284 | font-weight: 600; 285 | } 286 | .book.color-theme-2 .book-summary ul.summary li.active > a, 287 | .book.color-theme-2 .book-summary ul.summary li a:hover { 288 | color: #f4f4f5; 289 | background: #252737; 290 | font-weight: 600; 291 | } 292 | -------------------------------------------------------------------------------- /gitbook/plugins/gitbook-plugin-search/lunr.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.5.12 3 | * Copyright (C) 2015 Oliver Nightingale 4 | * MIT Licensed 5 | * @license 6 | */ 7 | !function(){var t=function(e){var n=new t.Index;return n.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),e&&e.call(n,n),n};t.version="0.5.12",t.utils={},t.utils.warn=function(t){return function(e){t.console&&console.warn&&console.warn(e)}}(this),t.EventEmitter=function(){this.events={}},t.EventEmitter.prototype.addListener=function(){var t=Array.prototype.slice.call(arguments),e=t.pop(),n=t;if("function"!=typeof e)throw new TypeError("last argument must be a function");n.forEach(function(t){this.hasHandler(t)||(this.events[t]=[]),this.events[t].push(e)},this)},t.EventEmitter.prototype.removeListener=function(t,e){if(this.hasHandler(t)){var n=this.events[t].indexOf(e);this.events[t].splice(n,1),this.events[t].length||delete this.events[t]}},t.EventEmitter.prototype.emit=function(t){if(this.hasHandler(t)){var e=Array.prototype.slice.call(arguments,1);this.events[t].forEach(function(t){t.apply(void 0,e)})}},t.EventEmitter.prototype.hasHandler=function(t){return t in this.events},t.tokenizer=function(t){return arguments.length&&null!=t&&void 0!=t?Array.isArray(t)?t.map(function(t){return t.toLowerCase()}):t.toString().trim().toLowerCase().split(/[\s\-]+/):[]},t.Pipeline=function(){this._stack=[]},t.Pipeline.registeredFunctions={},t.Pipeline.registerFunction=function(e,n){n in this.registeredFunctions&&t.utils.warn("Overwriting existing registered function: "+n),e.label=n,t.Pipeline.registeredFunctions[e.label]=e},t.Pipeline.warnIfFunctionNotRegistered=function(e){var n=e.label&&e.label in this.registeredFunctions;n||t.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},t.Pipeline.load=function(e){var n=new t.Pipeline;return e.forEach(function(e){var i=t.Pipeline.registeredFunctions[e];if(!i)throw new Error("Cannot load un-registered function: "+e);n.add(i)}),n},t.Pipeline.prototype.add=function(){var e=Array.prototype.slice.call(arguments);e.forEach(function(e){t.Pipeline.warnIfFunctionNotRegistered(e),this._stack.push(e)},this)},t.Pipeline.prototype.after=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._stack.indexOf(e);if(-1==i)throw new Error("Cannot find existingFn");i+=1,this._stack.splice(i,0,n)},t.Pipeline.prototype.before=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._stack.indexOf(e);if(-1==i)throw new Error("Cannot find existingFn");this._stack.splice(i,0,n)},t.Pipeline.prototype.remove=function(t){var e=this._stack.indexOf(t);-1!=e&&this._stack.splice(e,1)},t.Pipeline.prototype.run=function(t){for(var e=[],n=t.length,i=this._stack.length,o=0;n>o;o++){for(var r=t[o],s=0;i>s&&(r=this._stack[s](r,o,t),void 0!==r);s++);void 0!==r&&e.push(r)}return e},t.Pipeline.prototype.reset=function(){this._stack=[]},t.Pipeline.prototype.toJSON=function(){return this._stack.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})},t.Vector=function(){this._magnitude=null,this.list=void 0,this.length=0},t.Vector.Node=function(t,e,n){this.idx=t,this.val=e,this.next=n},t.Vector.prototype.insert=function(e,n){this._magnitude=void 0;var i=this.list;if(!i)return this.list=new t.Vector.Node(e,n,i),this.length++;if(en.idx?n=n.next:(i+=e.val*n.val,e=e.next,n=n.next);return i},t.Vector.prototype.similarity=function(t){return this.dot(t)/(this.magnitude()*t.magnitude())},t.SortedSet=function(){this.length=0,this.elements=[]},t.SortedSet.load=function(t){var e=new this;return e.elements=t,e.length=t.length,e},t.SortedSet.prototype.add=function(){var t,e;for(t=0;t1;){if(r===t)return o;t>r&&(e=o),r>t&&(n=o),i=n-e,o=e+Math.floor(i/2),r=this.elements[o]}return r===t?o:-1},t.SortedSet.prototype.locationFor=function(t){for(var e=0,n=this.elements.length,i=n-e,o=e+Math.floor(i/2),r=this.elements[o];i>1;)t>r&&(e=o),r>t&&(n=o),i=n-e,o=e+Math.floor(i/2),r=this.elements[o];return r>t?o:t>r?o+1:void 0},t.SortedSet.prototype.intersect=function(e){for(var n=new t.SortedSet,i=0,o=0,r=this.length,s=e.length,a=this.elements,h=e.elements;;){if(i>r-1||o>s-1)break;a[i]!==h[o]?a[i]h[o]&&o++:(n.add(a[i]),i++,o++)}return n},t.SortedSet.prototype.clone=function(){var e=new t.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},t.SortedSet.prototype.union=function(t){var e,n,i;return this.length>=t.length?(e=this,n=t):(e=t,n=this),i=e.clone(),i.add.apply(i,n.toArray()),i},t.SortedSet.prototype.toJSON=function(){return this.toArray()},t.Index=function(){this._fields=[],this._ref="id",this.pipeline=new t.Pipeline,this.documentStore=new t.Store,this.tokenStore=new t.TokenStore,this.corpusTokens=new t.SortedSet,this.eventEmitter=new t.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},t.Index.prototype.on=function(){var t=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,t)},t.Index.prototype.off=function(t,e){return this.eventEmitter.removeListener(t,e)},t.Index.load=function(e){e.version!==t.version&&t.utils.warn("version mismatch: current "+t.version+" importing "+e.version);var n=new this;return n._fields=e.fields,n._ref=e.ref,n.documentStore=t.Store.load(e.documentStore),n.tokenStore=t.TokenStore.load(e.tokenStore),n.corpusTokens=t.SortedSet.load(e.corpusTokens),n.pipeline=t.Pipeline.load(e.pipeline),n},t.Index.prototype.field=function(t,e){var e=e||{},n={name:t,boost:e.boost||1};return this._fields.push(n),this},t.Index.prototype.ref=function(t){return this._ref=t,this},t.Index.prototype.add=function(e,n){var i={},o=new t.SortedSet,r=e[this._ref],n=void 0===n?!0:n;this._fields.forEach(function(n){var r=this.pipeline.run(t.tokenizer(e[n.name]));i[n.name]=r,t.SortedSet.prototype.add.apply(o,r)},this),this.documentStore.set(r,o),t.SortedSet.prototype.add.apply(this.corpusTokens,o.toArray());for(var s=0;s0&&(i=1+Math.log(this.documentStore.length/n)),this._idfCache[e]=i},t.Index.prototype.search=function(e){var n=this.pipeline.run(t.tokenizer(e)),i=new t.Vector,o=[],r=this._fields.reduce(function(t,e){return t+e.boost},0),s=n.some(function(t){return this.tokenStore.has(t)},this);if(!s)return[];n.forEach(function(e,n,s){var a=1/s.length*this._fields.length*r,h=this,l=this.tokenStore.expand(e).reduce(function(n,o){var r=h.corpusTokens.indexOf(o),s=h.idf(o),l=1,u=new t.SortedSet;if(o!==e){var c=Math.max(3,o.length-e.length);l=1/Math.log(c)}return r>-1&&i.insert(r,a*s*l),Object.keys(h.tokenStore.get(o)).forEach(function(t){u.add(t)}),n.union(u)},new t.SortedSet);o.push(l)},this);var a=o.reduce(function(t,e){return t.intersect(e)});return a.map(function(t){return{ref:t,score:i.similarity(this.documentVector(t))}},this).sort(function(t,e){return e.score-t.score})},t.Index.prototype.documentVector=function(e){for(var n=this.documentStore.get(e),i=n.length,o=new t.Vector,r=0;i>r;r++){var s=n.elements[r],a=this.tokenStore.get(s)[e].tf,h=this.idf(s);o.insert(this.corpusTokens.indexOf(s),a*h)}return o},t.Index.prototype.toJSON=function(){return{version:t.version,fields:this._fields,ref:this._ref,documentStore:this.documentStore.toJSON(),tokenStore:this.tokenStore.toJSON(),corpusTokens:this.corpusTokens.toJSON(),pipeline:this.pipeline.toJSON()}},t.Index.prototype.use=function(t){var e=Array.prototype.slice.call(arguments,1);e.unshift(this),t.apply(this,e)},t.Store=function(){this.store={},this.length=0},t.Store.load=function(e){var n=new this;return n.length=e.length,n.store=Object.keys(e.store).reduce(function(n,i){return n[i]=t.SortedSet.load(e.store[i]),n},{}),n},t.Store.prototype.set=function(t,e){this.has(t)||this.length++,this.store[t]=e},t.Store.prototype.get=function(t){return this.store[t]},t.Store.prototype.has=function(t){return t in this.store},t.Store.prototype.remove=function(t){this.has(t)&&(delete this.store[t],this.length--)},t.Store.prototype.toJSON=function(){return{store:this.store,length:this.length}},t.stemmer=function(){var t={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},e={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},n="[^aeiou]",i="[aeiouy]",o=n+"[^aeiouy]*",r=i+"[aeiou]*",s="^("+o+")?"+r+o,a="^("+o+")?"+r+o+"("+r+")?$",h="^("+o+")?"+r+o+r+o,l="^("+o+")?"+i,u=new RegExp(s),c=new RegExp(h),f=new RegExp(a),d=new RegExp(l),p=/^(.+?)(ss|i)es$/,m=/^(.+?)([^s])s$/,v=/^(.+?)eed$/,y=/^(.+?)(ed|ing)$/,g=/.$/,S=/(at|bl|iz)$/,w=new RegExp("([^aeiouylsz])\\1$"),x=new RegExp("^"+o+i+"[^aeiouwxy]$"),k=/^(.+?[^aeiou])y$/,b=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,E=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,_=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,F=/^(.+?)(s|t)(ion)$/,O=/^(.+?)e$/,P=/ll$/,N=new RegExp("^"+o+i+"[^aeiouwxy]$"),T=function(n){var i,o,r,s,a,h,l;if(n.length<3)return n;if(r=n.substr(0,1),"y"==r&&(n=r.toUpperCase()+n.substr(1)),s=p,a=m,s.test(n)?n=n.replace(s,"$1$2"):a.test(n)&&(n=n.replace(a,"$1$2")),s=v,a=y,s.test(n)){var T=s.exec(n);s=u,s.test(T[1])&&(s=g,n=n.replace(s,""))}else if(a.test(n)){var T=a.exec(n);i=T[1],a=d,a.test(i)&&(n=i,a=S,h=w,l=x,a.test(n)?n+="e":h.test(n)?(s=g,n=n.replace(s,"")):l.test(n)&&(n+="e"))}if(s=k,s.test(n)){var T=s.exec(n);i=T[1],n=i+"i"}if(s=b,s.test(n)){var T=s.exec(n);i=T[1],o=T[2],s=u,s.test(i)&&(n=i+t[o])}if(s=E,s.test(n)){var T=s.exec(n);i=T[1],o=T[2],s=u,s.test(i)&&(n=i+e[o])}if(s=_,a=F,s.test(n)){var T=s.exec(n);i=T[1],s=c,s.test(i)&&(n=i)}else if(a.test(n)){var T=a.exec(n);i=T[1]+T[2],a=c,a.test(i)&&(n=i)}if(s=O,s.test(n)){var T=s.exec(n);i=T[1],s=c,a=f,h=N,(s.test(i)||a.test(i)&&!h.test(i))&&(n=i)}return s=P,a=c,s.test(n)&&a.test(n)&&(s=g,n=n.replace(s,"")),"y"==r&&(n=r.toLowerCase()+n.substr(1)),n};return T}(),t.Pipeline.registerFunction(t.stemmer,"stemmer"),t.stopWordFilter=function(e){return e&&t.stopWordFilter.stopWords[e]!==e?e:void 0},t.stopWordFilter.stopWords={a:"a",able:"able",about:"about",across:"across",after:"after",all:"all",almost:"almost",also:"also",am:"am",among:"among",an:"an",and:"and",any:"any",are:"are",as:"as",at:"at",be:"be",because:"because",been:"been",but:"but",by:"by",can:"can",cannot:"cannot",could:"could",dear:"dear",did:"did","do":"do",does:"does",either:"either","else":"else",ever:"ever",every:"every","for":"for",from:"from",get:"get",got:"got",had:"had",has:"has",have:"have",he:"he",her:"her",hers:"hers",him:"him",his:"his",how:"how",however:"however",i:"i","if":"if","in":"in",into:"into",is:"is",it:"it",its:"its",just:"just",least:"least",let:"let",like:"like",likely:"likely",may:"may",me:"me",might:"might",most:"most",must:"must",my:"my",neither:"neither",no:"no",nor:"nor",not:"not",of:"of",off:"off",often:"often",on:"on",only:"only",or:"or",other:"other",our:"our",own:"own",rather:"rather",said:"said",say:"say",says:"says",she:"she",should:"should",since:"since",so:"so",some:"some",than:"than",that:"that",the:"the",their:"their",them:"them",then:"then",there:"there",these:"these",they:"they","this":"this",tis:"tis",to:"to",too:"too",twas:"twas",us:"us",wants:"wants",was:"was",we:"we",were:"were",what:"what",when:"when",where:"where",which:"which","while":"while",who:"who",whom:"whom",why:"why",will:"will","with":"with",would:"would",yet:"yet",you:"you",your:"your"},t.Pipeline.registerFunction(t.stopWordFilter,"stopWordFilter"),t.trimmer=function(t){var e=t.replace(/^\W+/,"").replace(/\W+$/,"");return""===e?void 0:e},t.Pipeline.registerFunction(t.trimmer,"trimmer"),t.TokenStore=function(){this.root={docs:{}},this.length=0},t.TokenStore.load=function(t){var e=new this;return e.root=t.root,e.length=t.length,e},t.TokenStore.prototype.add=function(t,e,n){var n=n||this.root,i=t[0],o=t.slice(1);return i in n||(n[i]={docs:{}}),0===o.length?(n[i].docs[e.ref]=e,void(this.length+=1)):this.add(o,e,n[i])},t.TokenStore.prototype.has=function(t){if(!t)return!1;for(var e=this.root,n=0;n 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 | Commands | Introduction 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
70 | 71 | 72 |
73 | 451 |
452 | 453 |
454 |
455 | 465 | 466 |
467 |
468 | 469 | 470 |
471 | 472 |

Commands

473 |

sed 는 제공하는 명령이 몇개 되지 않기 때문에 원하는 결과를 얻기 위해서는 474 | sed 가 가지고 있는 기본 기능을 최대한 활용해야 합니다. 475 | 이때 각 명령들이 하는 역할을 명확하게 알고 있지 못하면 활용하기가 어렵습니다.

476 |

sed 는 모든 텍스트 조작을 regex 을 이용해 합니다. 477 | 그러므로 regex 을 잘 알고 활용할 수 있으면 sed 를 사용하는 것이 어렵지 않습니다. 478 | sed 를 하게 되면 좋은점 또한 regex 을 활용하는 법을 배울 수 있다는 점입니다.

479 |

아래는 sed 에서 사용되는 명령들인데요. 보기에는 많은것 같지만 대, 소문자로 중복되는 기능, 480 | 잘 사용하지 않는 명령들을 제외하면 실제 사용되는 명령은 몇개 되지 않습니다.

481 |

482 | 483 | 484 |
485 | 486 | 487 |
488 |
489 |
490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 |
498 |
499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 525 | 526 | 527 | 528 | 529 | 530 | -------------------------------------------------------------------------------- /escape_sequences.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 | Escape sequences | Introduction 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
70 | 71 | 72 |
73 | 451 |
452 | 453 |
454 |
455 | 465 | 466 |
467 |
468 | 469 | 470 |
471 | 472 |

Escape sequences

473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 |
Escape SequenceCharacter represented
\aalert (bell)
\fform feed
\nnewline
\rcarriage return
\thorizontal tab
\vvertical tab
\cxCtrl-x 문자, 가령 \cz 는 Ctrl-z (^Z)
\dNNN10 진수 ASCII 문자 NNN
\oNNN8 진수 ASCII 문자 NNN
\xHH16 진수 ASCII 문자 HH
523 |
524 |

\b (backspace) 는 regex 에서 word boundary (\b) 와 겹치므로 제외되었습니다.

525 |
526 |
# NUL 문자는 `\x0` 를 사용하면 됩니다.
527 | $ find ...  -print0 | sed -z 'N; s/\x0/.../'
528 | 
529 | # 유니코드 문자는 다음과 같이 shell 의 $' ' 을 사용하면 됩니다.
530 | $ echo aaa | sed 's/a/'$'\U2665''/g'
531 | ♥♥♥
532 | 
533 | 534 | 535 |
536 | 537 | 538 |
539 |
540 |
541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 |
549 |
550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 576 | 577 | 578 | 579 | 580 | 581 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 | Introduction | Introduction 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
68 | 69 | 70 |
71 | 449 |
450 | 451 |
452 |
453 | 463 | 464 |
465 |
466 | 467 | 468 |
469 | 470 |

471 |

Introduction

472 |

Shell 에서 제일 중요하고 기본이 되는 명령이 sed 입니다. 473 | 왜냐하면 모든 명령의 텍스트 출력을 sed 를 이용해 컨트롤할 수 있기 때문입니다. 474 | Unix 운영체제가 처음 만들어졌을 때 3 가지 주요 구성요소가 assembler, editor, shell 이였는데요. 475 | 당시에는 컴퓨터가 메모리도 적고, 모뎀 속도도 느리고, 콘솔로 teletype 같은 476 | 라인 프린터를 사용했기 때문에 라인 에디터를 사용하였습니다. 477 | 현재 리눅스에서도 볼수있는 /bin/ed 명령이 라인 에디터인데요. 478 | 이 라인 에디터가 이후에 sed, ex, vi, grep 같은 명령들의 기반이 됩니다. 479 | sed 는 ed 명령의 stream 버전으로 대부분 명령과 사용방법이 같습니다.

480 |
481 |

ex 명령은 ed 명령의 확장 버전으로 vi 에서 : 를 이용한 command mode 로 사용됩니다.
실제적으로 ex 명령의 visual mode 버전이 vi 입니다.

482 |
483 |
필요에 따라 수시로 업데이트 되므로 파일을 다운로드하는 것보다는 웹에서 보는 것이 좋습니다.
484 | 흰색 바탕이 너무 밝을 경우 좌측 상단에 보면 어두운 바탕으로 테마를 변경할 수 있습니다.
485 | ( 참고로 페이지는 Night 모드에서 작성하였습니다. )
486 | 
487 | 488 |
489 | 490 | 491 |
492 |
493 |
494 | 495 | 496 | 497 | 498 | 499 |
500 |
501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 527 | 528 | 529 | 530 | 531 | 532 | -------------------------------------------------------------------------------- /bug_reports.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 | Bug reports | Introduction 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
70 | 71 | 72 |
73 | 451 |
452 | 453 |
454 |
455 | 465 | 466 |
467 |
468 | 469 | 470 |
471 | 472 |

Bug reports

473 |

책 내용 중에 수정, 보완해야 될 부분이 있거나 또는 추가하면 좋을 내용이 있으시면
아래 github issues 게시판을 통해 알려주시면 감사하겠습니다.

474 |

https://github.com/mug896/sed-stream-editor/issues

475 |
476 |

Bash shell script 가이드

477 | 478 | 479 | 487 |
480 | 481 |

github

482 | https://mug896.github.io/bash-shell 483 | 484 |

github 게시판

485 | https://github.com/mug896/bash-shell/issues 486 |
488 | 489 | 490 |

Sed stream editor 가이드

491 | 492 | 493 | 501 |
494 | 495 |

github

496 | https://mug896.github.io/sed-stream-editor 497 | 498 |

github 게시판

499 | https://github.com/mug896/sed-stream-editor/issues 500 |
502 | 503 | 504 | 505 |

AWK script 가이드

506 | 507 | 508 | 516 |
509 | 510 |

github

511 | https://mug896.github.io/awk-script 512 | 513 |

github 게시판

514 | https://github.com/mug896/awk-script/issues 515 |
517 | 518 | 519 |

Make script 가이드

520 | 521 | 522 | 530 |
523 | 524 |

github

525 | https://mug896.github.io/make-script 526 | 527 |

github 게시판

528 | https://github.com/mug896/make-script/issues 529 |
531 | 532 | 533 | 534 | 535 |

Macro 가이드

536 | 537 | 538 | 546 |
539 | 540 |

github

541 | https://mug896.github.io/macro 542 | 543 |

github 게시판

544 | https://github.com/mug896/macro/issues 545 |
547 | 548 | 549 | 550 |
551 | 552 | 553 |
554 |
555 |
556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 |
564 |
565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 591 | 592 | 593 | 594 | 595 | 596 | -------------------------------------------------------------------------------- /print.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 | print | Introduction 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
70 | 71 | 72 |
73 | 451 |
452 | 453 |
454 |
455 | 465 | 466 |
467 |
468 | 469 | 470 |
471 | 472 |

Print

473 |

474 |
1. 현재 pattern space 에 있는 내용을 프린트합니다.
475 |

p 명령은 주로 -n 옵션과 함께 사용됩니다. 476 | -n 옵션을 사용하지 않은 상태에서 p 명령을 사용하면 p 명령에 의해 한번, 477 | 명령 사이클이 끝날때 sed 에 의해 한번, 두번 pattern space 의 내용이 출력됩니다.

478 |
$ seq 111 111 555 | sed '3p'
479 | 111
480 | 222
481 | 333
482 | 333      # '-n' 옵션을 사용하지 않은 상태이므로 3번 라인이 두번 출력
483 | 444
484 | 555
485 | 
486 |

라인이 pattern space 에 입,출력 되는 과정

487 |

488 |

새로운 명령 사이클이 시작되거나 아니면 n, N 명령에 의해 489 | 입력 스트림으로 부터 라인이 하나 pattern space 에 입력되면 위 그림에서 1번 상태가 됩니다. 490 | 이때 한가지 주목해야 될 점은 newline 이 pattern space 밖으로 제외된다는 점입니다. 491 | 그러므로 수정 명령이 적용될때 newline 은 포함되지 않습니다. 492 | 사용자가 입력한 명령들이 pattern space 에 적용되고 명령 사이클이 끝나거나, 아니면 493 | 사이클 중에 p 명령을 실행했을 경우 그림 2번 에서와 같이 현재 pattern space 에 있는 내용과 494 | 제외되었던 newline 더해져서 출력됩니다.

495 |

위의 경우는 입력되는 라인에 newline 이 포함되는 일반적인 경우에 해당합니다. 496 | 가령 bash 에서 echo -n 111 명령을 사용하게 되면 출력에 newline 이 포함되지 않게 되는데요. 497 | 이때는 sed 명령의 출력에도 newline 이 포함되지 않게 되므로 개행이 되지 않습니다.

498 |
$ echo 111 | sed ''                  
499 | 111                                  # 입력되는 라인에 newline 이 포함되는 경우
500 | mug896@EliteBook [pts/7] ~/tmp
501 | 
502 | $ echo -n 111 | sed ''               # echo 명령에 -n 옵션을 사용
503 | 111mug896@EliteBook [pts/7] ~/tmp    # 입력되는 라인에 newline 이 없으므로
504 | $                                    # 출력때 개행이 되지 않는다.
505 | 
506 |

명령 사이클이 끝나거나, p 명령에 의해서 pattern space 에 있는 내용이 프린트될 때는 507 | 현재 pattern space 에 있는 전체 내용이 프린트됩니다.

508 |

509 |

510 |
1. pattern space 에서 첫번째 라인만 프린트합니다.
511 |

pattern space 에 라인이 하나뿐이 없으면 p 명령과 차이가 없습니다. 512 | 이 명령은 주로 multiple lines 를 다룰 때 pattern space 에서 첫 번째 라인을 삭제하는 D 명령과 함께 사용됩니다.

513 |

514 | 515 | 516 |
517 | 518 | 519 |
520 |
521 |
522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 |
530 |
531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 557 | 558 | 559 | 560 | 561 | 562 | -------------------------------------------------------------------------------- /debugging.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 | Debugging | Introduction 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
70 | 71 | 72 |
73 | 451 |
452 | 453 |
454 |
455 | 465 | 466 |
467 |
468 | 469 | 470 |
471 | 472 |

Debugging

473 |

sed 는 따로 디버깅을 위한 옵션이나 기능을 제공하지 않습니다. 474 | 따라서 디버깅을 하려면 직접 p 명령을 이용해서 pattern space 에 있는 내용을 조회해야 하는데요. 475 | 그런데 p 명령은 printable 문자만 표시되기 때문에 내용 중에 476 | non-printable 문자가 사용됐을 때는 정확한 값을 확인할 수가 없습니다. 477 | 따라서 sed 는 디버깅에 활용할 수 있도록 다음과 같은 명령을 제공합니다.

478 |

479 |

pattern space 에 있는 내용을 escape sequence 를 이용해 표시해줍니다.

480 |
# '\a' 은 non-printable 문자로 아예 값이 표시되지 않는다.
481 | # '\t', '\v' 값은 space, newline 과 구분하기가 어렵다.
482 | $ echo -e "valX\a111\nvalY\t222\nvalZ\v333" | sed -En 'N;N;p'
483 | valX111
484 | valY    222
485 | valZ
486 |     333
487 | 
488 | # 'l' 명령을 사용하면 escape sequence 를 이용해 값을 있는 그대로 표시해줍니다.
489 | $ echo -e "valX\a111\nvalY\t222\nvalZ\v333" | sed -En 'N;N;l'
490 | valX\a111\nvalY\t222\nvalZ\v333$
491 | 
492 |
493 |

l 명령은 출력이 newline 문자에 의해 개행이 되지 않기 때문에 따로 line-wrap length 값을 사용해 개행하는데요. 494 | sed 명령의 -l N 옵션을 통해서 값을 설정할 수 있습니다.

495 |
496 |

l 명령을 활용한 디버깅 예제

497 |

다음은 데이터 파일에 숫자 라인과 알파벳 라인이 혼합되어 있을 경우 498 | 숫자 라인 다음에 알파벳 라인이 올 경우만 값을 표시하는 스크립트입니다. 499 | 이때 l 명령을 이용함으로써 매 라인 입력 시마다 변경되는 pattern space 의 값을 500 | 조회해 볼수 있습니다.

501 |
$ cat file
502 | 111
503 | 222
504 | ABC
505 | 333
506 | 444
507 | DEF
508 | 555
509 | 
510 | # 숫자 라인 다음에 알파벳 라인이 올 경우 프린트
511 | $ sed -En '$!N; /[0-9]+\n[A-Z]+/p; D' file
512 | 222
513 | ABC
514 | 444
515 | DEF
516 | 
517 | # 'l' 명령을 이용함으로써 pattern space 의 내용을 확인할 수 있다.
518 | $ sed -En '$!N; l; /[0-9]+\n[A-Z]+/p; D' file
519 | 111\n222$
520 | 222\nABC$  <---- match !
521 | 222
522 | ABC
523 | ABC\n333$
524 | 333\n444$
525 | 444\nDEF$  <---- match !
526 | 444
527 | DEF
528 | DEF\n555$
529 | 555$
530 | 
531 |
532 |

$ 문자는 pattern space 의 끝을 나타냅니다.

533 |
534 |

535 |

현재 pattern space 에 입력된 라인넘버를 표시해줍니다.

536 |
$ echo -e "valX\a111\nvalY\t222\nvalZ\v333\nvalA:444" | sed -E '='   
537 | 1
538 | valX111
539 | 2
540 | valY    222
541 | 3
542 | valZ
543 |     333
544 | 4
545 | valA:444
546 | 
547 | $ echo -e "valX\a111\nvalY\t222\nvalZ\v333\nvalA:444" | sed -E 'N;=' 
548 | 2
549 | valX111
550 | valY    222
551 | 4
552 | valZ
553 |     333
554 | valA:444
555 | 
556 |

Regex 테스트

557 |

https://regex101.com/ 사이트를 활용하면 도움이 됩니다.

558 |

https://regexper.com/ regex railroad diagram generator

559 | 560 | 561 |
562 | 563 | 564 |
565 |
566 |
567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 |
575 |
576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 602 | 603 | 604 | 605 | 606 | 607 | -------------------------------------------------------------------------------- /delete.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 | delete | Introduction 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
70 | 71 | 72 |
73 | 451 |
452 | 453 |
454 |
455 | 465 | 466 |
467 |
468 | 469 | 470 |
471 | 472 |

Delete

473 |

474 |
1. pattern space 에 있는 내용을 전부 삭제합니다.
475 |
2. pattern space 에 데이터가 없으므로 명령 사이클을 중단하고 다음 사이클을 시작합니다.
476 |
3. 읽어들일 라인이 없으면 exit 합니다.
477 |

d 명령을 사용할 때 기억해야 될 것은 명령이 실행되면 현재 사이클이 중단되고 478 | 새로운 사이클을 시작한다는 것입니다. 만약에 pattern space 삭제후 현재 위치에서 479 | 실행을 계속하려면 z 명령 을 사용할 수 있습니다.

480 |

481 |

482 |
1. pattern space 에서 첫 번째 라인을 삭제합니다.
483 |
2. 명령 사이클의 BEGIN 위치로 가서 다음 사이클을 시작합니다. ( 이때 라인을 읽어들이지 않습니다 )
484 |
3. pattern space 에 라인이 하나만 남았을 경우는 d 명령과 같은 역할을 합니다.
485 |

이 명령은 multiple lines 을 처리할 때 사용하는 명령으로 pattern space 에 라인이 하나만 486 | 남았을 경우는 삭제되면 이어지는 명령에서 처리할 데이터가 없으므로 d 명령과 같은 역할을 합니다.

487 |

488 |

예제 1

489 |

파일 내용중에 구분자로 사용되는 스트링값 --- 이 여러군대 나올 수 있는데 490 | 마지막 구분자 이후의 내용만 출력하는것 입니다.

491 |
$ cat file
492 | 111
493 | 222
494 | 333
495 | ---
496 | 444
497 | 555
498 | 666
499 | ---
500 | 777
501 | 888
502 | 999
503 | 
504 | $ sed -E '
505 |     :X          # 레이블 X 를 지정
506 |     /---$/d     # pattern space 의 마지막 라인 그러니까 가장 최근에 append 한 라인이
507 |                 # "---" 구분자 일경우 d 명령으로 pattern space 를 모두 삭제하고 새로운 사이클 시작
508 |     N           # N 명령으로 다음 라인을 읽어들여 pattern space 에 append
509 |     bX          # 레이블 X 로 (b) 분기
510 | }' file
511 | 
512 | 777
513 | 888
514 | 999
515 | 
516 |

예제 2

517 |

[FILE] 아래 [LINE] 이 없는 경우 삭제합니다. [LINE] 은 모두 표시합니다.

518 |
$ cat file
519 | [FILE]: C:\Users\user\git\build.xml
520 | [FILE]: C:\Users\user\git\dataload-pom.xml
521 | [FILE]: C:\Users\user\git\local.properties
522 |     [LINE]:  [job.mail.toAddress=]
523 |     [LINE]:  [log.mail.toAddress=]
524 |     [LINE]:  [log.mail.client.toAddress=]
525 |     [LINE]:  [bill.report.toAddress=]
526 | [FILE]: C:\Users\user\git\pom.xml
527 | [FILE]: C:\Users\user\git\release.properties
528 |     [LINE]:  [job.mail.toAddress=]
529 |     [LINE]:  [log.mail.client.toAddress=]
530 | .............................................
531 | 
532 | $ sed -E '
533 |     /\[FILE]/{             # [FILE] 라인이 입력되면 
534 |         N                  # `N` 명령으로 다음 라인을 pattern space 에 append
535 | 
536 |         /\n\[FILE]: /D     # 두 번째 라인도 [FILE] 라인일 경우 `D` 명령으로
537 |                            # 첫 번째 라인을 삭제하고 명령 사이클의 BEGIN 으로 분기
538 |     }
539 | ' file
540 | 
541 | [FILE]: C:\Users\user\git\local.properties
542 |     [LINE]:  [job.mail.toAddress=]
543 |     [LINE]:  [log.mail.toAddress=]
544 |     [LINE]:  [log.mail.client.toAddress=]
545 |     [LINE]:  [bill.report.toAddress=]
546 | [FILE]: C:\Users\user\git\release.properties
547 |     [LINE]:  [job.mail.toAddress=]
548 |     [LINE]:  [log.mail.client.toAddress=]
549 | 
550 | 551 | 552 |
553 | 554 | 555 |
556 |
557 |
558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 |
566 |
567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 593 | 594 | 595 | 596 | 597 | 598 | -------------------------------------------------------------------------------- /and_or_not.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 | AND, OR, NOT | Introduction 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
70 | 71 | 72 |
73 | 451 |
452 | 453 |
454 |
455 | 465 | 466 |
467 |
468 | 469 | 470 |
471 | 472 |

AND, OR, NOT

473 |

sed 는 간단히 사칙연산을 할 수 있는 연산자도 없을뿐더러 AND, OR 연산자도 없습니다.
하지만 sed 의 기본기능을 활용하면 AND, OR 연산을 처리할 수가 있습니다.

474 |

AND

475 |

AND 연산은 보통 프로그래밍 언어에서 && 연산자로 표현되는데요.
sed 에서는 다음과 같은 방식으로 AND 연산 결과를 얻을 수 있습니다.

476 |
AA && BB
477 |
$ echo "AA 11 BB 22 CC" | sed -n '/AA/{ /BB/p }'
478 | AA 11 BB 22 CC
479 | 
480 |
AA && BB && CC
481 |
$ echo "AA 11 BB 22 CC" | sed -n '/AA/{ /BB/{ /CC/p } }'
482 | AA 11 BB 22 CC
483 | 
484 |

OR

485 |

OR 연산은 프로그래밍 언어에서 || 연산자에 해당하는데요.
sed 에서는 regex 에서 제공하는 | 연산자를 이용할 수 있습니다.

486 |
AA || BB
487 |
$ echo "11 BB 22 CC 33" | sed -En '/AA|BB/p'
488 | 11 BB 22 CC 33
489 | 
490 | $ echo "11 BB 22 CC 33" | sed -En -e '/AA/{bX}; /BB/{bX}; b' -e ':X p'
491 | 11 BB 22 CC 33
492 | 
493 |
AA || BB || CC
494 |
$ echo "11 CC 22 DD 33" | sed -En '/AA|BB|CC/p'
495 | 11 CC 22 DD 33
496 | 
497 | $ echo "11 CC 22 DD 33" | sed -En -e '/AA/{bX}; /BB/{bX}; /CC/{bX}; b' -e ':X p'
498 | AA 11 BB 22 CC
499 | 
500 |

AND, OR

501 |
AA && ( 11 || 22 )
502 |
$ echo "AA 22 BB 33 CC" | sed -En '/AA/{ /11|22/p }'
503 | AA 22 BB 33 CC
504 | 
505 |
AA && BB && ( 11 || 22 || 33 )
506 |
$ echo "AA 33 BB 44 CC" | sed -En '/AA/{ /BB/{ /11|22|33/p } }'
507 | AA 33 BB 44 CC
508 | 
509 |
AA || ( 11 && 22 )
510 |
$ echo "BB 11 CC 22 DD" | sed -En -e '/AA/{bX}; /11/{ /22/{bX} }; b' -e ':X p'
511 | BB 11 CC 22 DD
512 | 
513 |
AA || BB || ( 11 && 22 && 33 )
514 |
$ echo "11 CC 22 DD 33" | sed -En -e '/AA|BB/{bX}; /11/{ /22/{ /33/{bX} } }; b' -e ':X p'
515 | 11 CC 22 DD 33
516 | 
517 |

NOT

518 |

/.../ 뒤에 ! 문자를 붙이면 logical NOT 이 됩니다.

519 |
# 라인이 foo 로 시작하지 않을 경우 맨앞 또는 맨뒤에 'X' 를 붙인다.
520 | $ echo "goobar 111 222" | sed -E '/^foo/! s/^|$/X/g'
521 | Xgoobar 111 222X
522 | 
523 | # 뒤 이어지는 명령이 두 개 이상일 경우는 다음과 같이 { } 를 사용해야 합니다.
524 | $ echo "goobar 111 222" | sed -E '/^foo/! { s/^|$/X/g; s/111/aaa/ }'
525 | Xgoobar aaa 222X
526 | 
527 | $ echo "foobar 111 222" | sed -E '/^foo/! s/^|$/X/g'
528 | foobar 111 222
529 | 
530 | # 다음식은 모두 동일한 것으로 공백라인 또는 '#' 문자로 시작하지 않을 경우 프린트됩니다.
531 | sed -En '/^\s*$|^#/!p'
532 | 
533 | sed -En '/^\s*$/!{ /^#/!p }'
534 | 
535 | sed -En '/^#/!{ /^\s*$/!p }'
536 | 
537 |

예제 1

538 |

데이터 파일 내용 중에서 rocommunity 가 있는 라인을 삭제합니다.
그런데 라인이 127.0.0.1 를 포함하고 있으면 삭제하지 않고 프린트합니다.

539 |
$ cat file
540 | rocommunity hedona 127.0.0.1
541 | rocommunity hedona linux1 
542 | rocommunity hedona linux12
543 | rocommunity hedona linux13
544 | rocommunity hedona linux15
545 | rocommunity hedona linux16
546 | rocommunity hedona linux17
547 | syscontact linux 67
548 | syslocation UNKNOWN
549 | trapcommunity hedona
550 | trapsink  linux76 parshedona
551 | 
552 | $ sed '/rocommunity/{ /127\.0\.0\.1/!d }' file
553 | rocommunity hedona 127.0.0.1
554 | syscontact linux 67
555 | syslocation UNKNOWN
556 | trapcommunity hedona
557 | trapsink  linux76 parshedona
558 | 
559 | 560 | 561 |
562 | 563 | 564 |
565 |
566 |
567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 |
575 |
576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 602 | 603 | 604 | 605 | 606 | 607 | --------------------------------------------------------------------------------