You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 404.html
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@
32
32
}
33
33
html.classList.remove('sidebar-visible');
34
34
html.classList.add("sidebar-"+sidebar);
35
-
</script><navid=sidebarclass=sidebararia-label="Table of contents"><divclass=sidebar-scrollbox><olclass=chapter><liclass="chapter-item expanded affix"><ahref=preface.html>Preface</a><liclass="chapter-item expanded"><ahref=cat-tac.html><strongaria-hidden=true>1.</strong> cat and tac</a></li><br><hr><liclass="chapter-item expanded"><iid=git-repository-buttonclass="fa fa-github"></i><ahref=https://github.com/learnbyexample/cli_text_processing_coreutils> Source code</a><liclass="chapter-item expanded"><iid=home-buttonclass="fa fa-home"></i><ahref=https://learnbyexample.github.io/> My Blog</a><liclass="chapter-item expanded"><iid=book-buttonclass="fa fa-book"></i><ahref=https://learnbyexample.github.io/books/> My Books</a></ol></div><divid=sidebar-resize-handleclass=sidebar-resize-handle></div></nav><divid=page-wrapperclass=page-wrapper><divclass=page><divid=menu-bar-hover-placeholder></div><divid=menu-barclass="menu-bar sticky bordered"><divclass=left-buttons><buttonid=sidebar-toggleclass=icon-buttontype=buttontitle="Toggle Table of Contents"aria-label="Toggle Table of Contents"aria-controls=sidebar><iclass="fa fa-bars"></i></button><buttonid=theme-toggleclass=icon-buttontype=buttontitle="Change theme"aria-label="Change theme"aria-haspopup=truearia-expanded=falsearia-controls=theme-list><iclass="fa fa-paint-brush"></i></button><ulid=theme-listclass=theme-popuparia-label=Themesrole=menu><lirole=none><buttonrole=menuitemclass=themeid=light>Light (default)</button><lirole=none><buttonrole=menuitemclass=themeid=rust>Rust</button><lirole=none><buttonrole=menuitemclass=themeid=coal>Coal</button><lirole=none><buttonrole=menuitemclass=themeid=navy>Navy</button><lirole=none><buttonrole=menuitemclass=themeid=ayu>Ayu</button></ul><buttonid=search-toggleclass=icon-buttontype=buttontitle="Search. (Shortkey: s)"aria-label="Toggle Searchbar"aria-expanded=falsearia-keyshortcuts=Saria-controls=searchbar><iclass="fa fa-search"></i></button></div><h1class=menu-title>Command line text processing with GNU Coreutils</h1><divclass=right-buttons><ahref=https://learnbyexample.github.iotitle=Blogaria-label=Blog><iid=home-buttonclass="fa fa-home"></i></a><ahref=https://github.com/learnbyexample/cli_text_processing_coreutilstitle="Git repository"aria-label="Git repository"><iid=git-repository-buttonclass="fa fa-github"></i></a></div></div><divid=search-wrapperclass=hidden><formid=searchbar-outerclass=searchbar-outer><inputtype=searchid=searchbarname=searchbarplaceholder="Search this book ..."aria-controls=searchresults-outeraria-describedby=searchresults-header></form><divid=searchresults-outerclass="searchresults-outer hidden"><divid=searchresults-headerclass=searchresults-header></div><ulid=searchresults></ul></div></div><script>
35
+
</script><navid=sidebarclass=sidebararia-label="Table of contents"><divclass=sidebar-scrollbox><olclass=chapter><liclass="chapter-item expanded affix"><ahref=preface.html>Preface</a><liclass="chapter-item expanded"><ahref=cat-tac.html><strongaria-hidden=true>1.</strong> cat and tac</a><liclass="chapter-item expanded"><ahref=head-tail.html><strongaria-hidden=true>2.</strong> head and tail</a></li><br><hr><liclass="chapter-item expanded"><iid=git-repository-buttonclass="fa fa-github"></i><ahref=https://github.com/learnbyexample/cli_text_processing_coreutils> Source code</a><liclass="chapter-item expanded"><iid=home-buttonclass="fa fa-home"></i><ahref=https://learnbyexample.github.io/> My Blog</a><liclass="chapter-item expanded"><iid=book-buttonclass="fa fa-book"></i><ahref=https://learnbyexample.github.io/books/> My Books</a></ol></div><divid=sidebar-resize-handleclass=sidebar-resize-handle></div></nav><divid=page-wrapperclass=page-wrapper><divclass=page><divid=menu-bar-hover-placeholder></div><divid=menu-barclass="menu-bar sticky bordered"><divclass=left-buttons><buttonid=sidebar-toggleclass=icon-buttontype=buttontitle="Toggle Table of Contents"aria-label="Toggle Table of Contents"aria-controls=sidebar><iclass="fa fa-bars"></i></button><buttonid=theme-toggleclass=icon-buttontype=buttontitle="Change theme"aria-label="Change theme"aria-haspopup=truearia-expanded=falsearia-controls=theme-list><iclass="fa fa-paint-brush"></i></button><ulid=theme-listclass=theme-popuparia-label=Themesrole=menu><lirole=none><buttonrole=menuitemclass=themeid=light>Light (default)</button><lirole=none><buttonrole=menuitemclass=themeid=rust>Rust</button><lirole=none><buttonrole=menuitemclass=themeid=coal>Coal</button><lirole=none><buttonrole=menuitemclass=themeid=navy>Navy</button><lirole=none><buttonrole=menuitemclass=themeid=ayu>Ayu</button></ul><buttonid=search-toggleclass=icon-buttontype=buttontitle="Search. (Shortkey: s)"aria-label="Toggle Searchbar"aria-expanded=falsearia-keyshortcuts=Saria-controls=searchbar><iclass="fa fa-search"></i></button></div><h1class=menu-title>Command line text processing with GNU Coreutils</h1><divclass=right-buttons><ahref=https://learnbyexample.github.iotitle=Blogaria-label=Blog><iid=home-buttonclass="fa fa-home"></i></a><ahref=https://github.com/learnbyexample/cli_text_processing_coreutilstitle="Git repository"aria-label="Git repository"><iid=git-repository-buttonclass="fa fa-github"></i></a></div></div><divid=search-wrapperclass=hidden><formid=searchbar-outerclass=searchbar-outer><inputtype=searchid=searchbarname=searchbarplaceholder="Search this book ..."aria-controls=searchresults-outeraria-describedby=searchresults-header></form><divid=searchresults-outerclass="searchresults-outer hidden"><divid=searchresults-headerclass=searchresults-header></div><ulid=searchresults></ul></div></div><script>
Copy file name to clipboardExpand all lines: cat-tac.html
+12-5Lines changed: 12 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@
32
32
}
33
33
html.classList.remove('sidebar-visible');
34
34
html.classList.add("sidebar-"+sidebar);
35
-
</script><navid=sidebarclass=sidebararia-label="Table of contents"><divclass=sidebar-scrollbox><olclass=chapter><liclass="chapter-item expanded affix"><ahref=preface.html>Preface</a><liclass="chapter-item expanded"><ahref=cat-tac.htmlclass=active><strongaria-hidden=true>1.</strong> cat and tac</a></li><br><hr><liclass="chapter-item expanded"><iid=git-repository-buttonclass="fa fa-github"></i><ahref=https://github.com/learnbyexample/cli_text_processing_coreutils> Source code</a><liclass="chapter-item expanded"><iid=home-buttonclass="fa fa-home"></i><ahref=https://learnbyexample.github.io/> My Blog</a><liclass="chapter-item expanded"><iid=book-buttonclass="fa fa-book"></i><ahref=https://learnbyexample.github.io/books/> My Books</a></ol></div><divid=sidebar-resize-handleclass=sidebar-resize-handle></div></nav><divid=page-wrapperclass=page-wrapper><divclass=page><divid=menu-bar-hover-placeholder></div><divid=menu-barclass="menu-bar sticky bordered"><divclass=left-buttons><buttonid=sidebar-toggleclass=icon-buttontype=buttontitle="Toggle Table of Contents"aria-label="Toggle Table of Contents"aria-controls=sidebar><iclass="fa fa-bars"></i></button><buttonid=theme-toggleclass=icon-buttontype=buttontitle="Change theme"aria-label="Change theme"aria-haspopup=truearia-expanded=falsearia-controls=theme-list><iclass="fa fa-paint-brush"></i></button><ulid=theme-listclass=theme-popuparia-label=Themesrole=menu><lirole=none><buttonrole=menuitemclass=themeid=light>Light (default)</button><lirole=none><buttonrole=menuitemclass=themeid=rust>Rust</button><lirole=none><buttonrole=menuitemclass=themeid=coal>Coal</button><lirole=none><buttonrole=menuitemclass=themeid=navy>Navy</button><lirole=none><buttonrole=menuitemclass=themeid=ayu>Ayu</button></ul><buttonid=search-toggleclass=icon-buttontype=buttontitle="Search. (Shortkey: s)"aria-label="Toggle Searchbar"aria-expanded=falsearia-keyshortcuts=Saria-controls=searchbar><iclass="fa fa-search"></i></button></div><h1class=menu-title>Command line text processing with GNU Coreutils</h1><divclass=right-buttons><ahref=https://learnbyexample.github.iotitle=Blogaria-label=Blog><iid=home-buttonclass="fa fa-home"></i></a><ahref=https://github.com/learnbyexample/cli_text_processing_coreutilstitle="Git repository"aria-label="Git repository"><iid=git-repository-buttonclass="fa fa-github"></i></a></div></div><divid=search-wrapperclass=hidden><formid=searchbar-outerclass=searchbar-outer><inputtype=searchid=searchbarname=searchbarplaceholder="Search this book ..."aria-controls=searchresults-outeraria-describedby=searchresults-header></form><divid=searchresults-outerclass="searchresults-outer hidden"><divid=searchresults-headerclass=searchresults-header></div><ulid=searchresults></ul></div></div><script>
35
+
</script><navid=sidebarclass=sidebararia-label="Table of contents"><divclass=sidebar-scrollbox><olclass=chapter><liclass="chapter-item expanded affix"><ahref=preface.html>Preface</a><liclass="chapter-item expanded"><ahref=cat-tac.htmlclass=active><strongaria-hidden=true>1.</strong> cat and tac</a><liclass="chapter-item expanded"><ahref=head-tail.html><strongaria-hidden=true>2.</strong> head and tail</a></li><br><hr><liclass="chapter-item expanded"><iid=git-repository-buttonclass="fa fa-github"></i><ahref=https://github.com/learnbyexample/cli_text_processing_coreutils> Source code</a><liclass="chapter-item expanded"><iid=home-buttonclass="fa fa-home"></i><ahref=https://learnbyexample.github.io/> My Blog</a><liclass="chapter-item expanded"><iid=book-buttonclass="fa fa-book"></i><ahref=https://learnbyexample.github.io/books/> My Books</a></ol></div><divid=sidebar-resize-handleclass=sidebar-resize-handle></div></nav><divid=page-wrapperclass=page-wrapper><divclass=page><divid=menu-bar-hover-placeholder></div><divid=menu-barclass="menu-bar sticky bordered"><divclass=left-buttons><buttonid=sidebar-toggleclass=icon-buttontype=buttontitle="Toggle Table of Contents"aria-label="Toggle Table of Contents"aria-controls=sidebar><iclass="fa fa-bars"></i></button><buttonid=theme-toggleclass=icon-buttontype=buttontitle="Change theme"aria-label="Change theme"aria-haspopup=truearia-expanded=falsearia-controls=theme-list><iclass="fa fa-paint-brush"></i></button><ulid=theme-listclass=theme-popuparia-label=Themesrole=menu><lirole=none><buttonrole=menuitemclass=themeid=light>Light (default)</button><lirole=none><buttonrole=menuitemclass=themeid=rust>Rust</button><lirole=none><buttonrole=menuitemclass=themeid=coal>Coal</button><lirole=none><buttonrole=menuitemclass=themeid=navy>Navy</button><lirole=none><buttonrole=menuitemclass=themeid=ayu>Ayu</button></ul><buttonid=search-toggleclass=icon-buttontype=buttontitle="Search. (Shortkey: s)"aria-label="Toggle Searchbar"aria-expanded=falsearia-keyshortcuts=Saria-controls=searchbar><iclass="fa fa-search"></i></button></div><h1class=menu-title>Command line text processing with GNU Coreutils</h1><divclass=right-buttons><ahref=https://learnbyexample.github.iotitle=Blogaria-label=Blog><iid=home-buttonclass="fa fa-home"></i></a><ahref=https://github.com/learnbyexample/cli_text_processing_coreutilstitle="Git repository"aria-label="Git repository"><iid=git-repository-buttonclass="fa fa-github"></i></a></div></div><divid=search-wrapperclass=hidden><formid=searchbar-outerclass=searchbar-outer><inputtype=searchid=searchbarname=searchbarplaceholder="Search this book ..."aria-controls=searchresults-outeraria-describedby=searchresults-header></form><divid=searchresults-outerclass="searchresults-outer hidden"><divid=searchresults-headerclass=searchresults-header></div><ulid=searchresults></ul></div></div><script>
</code></pre><p><strong>Here Documents</strong> is another popular way to create such files. Especially inside shell scripts, since pressing <code>Ctrl+d</code> interactively won't be possible. Here's an example:<pre><codeclass=language-bash># > and a space at the start of lines are only present in interactive mode
49
49
# won't be needed in a shell script
50
50
# EOF is typically used as the identifier
51
-
$ cat << 'EOF' > fruits.txt
51
+
$ cat << 'EOF' > fruits.txt
52
52
> banana
53
53
> papaya
54
54
> mango
@@ -58,7 +58,14 @@
58
58
banana
59
59
papaya
60
60
mango
61
-
</code></pre><p>The termination string is enclosed in single quotes to prevent parameter expansion, command substitution, etc. You can also use <code>\string</code> for this purpose. If you use <code><<-</code> instead of <code><<</code>, you can use leading tab characters for indentation purposes. See <ahref=https://www.gnu.org/software/bash/manual/bash.html#Here-Documents>bash manual: Here Documents</a> and <ahref=https://stackoverflow.com/q/2953081/4082052>stackoverflow: here-documents</a> for more details.<h2id=concatenate-files><aclass=headerhref=#concatenate-files>Concatenate files</a></h2><p>Here's some examples to showcase <code>cat</code>'s main utility. One or more files can be given as arguments.<pre><codeclass=language-bash>$ cat greeting.txt fruits.txt nums.txt
61
+
</code></pre><p>The termination string is enclosed in single quotes to prevent parameter expansion, command substitution, etc. You can also use <code>\string</code> for this purpose. If you use <code><<-</code> instead of <code><<</code>, you can use leading tab characters for indentation purposes. See <ahref=https://www.gnu.org/software/bash/manual/bash.html#Here-Documents>bash manual: Here Documents</a> and <ahref=https://stackoverflow.com/q/2953081/4082052>stackoverflow: here-documents</a> for more details.<blockquote><p><imgsrc=./images/info.svgalt=info> Note that creating files as shown above isn't restricted to <code>cat</code>, it can be applied to any command waiting for <code>stdin</code>.</blockquote><pre><codeclass=language-bash>$ tr 'a-z' 'A-Z' << 'end' > op.txt
62
+
> hi there
63
+
> have a nice day
64
+
> end
65
+
$ cat op.txt
66
+
HI THERE
67
+
HAVE A NICE DAY
68
+
</code></pre><h2id=concatenate-files><aclass=headerhref=#concatenate-files>Concatenate files</a></h2><p>Here's some examples to showcase <code>cat</code>'s main utility. One or more files can be given as arguments.<pre><codeclass=language-bash>$ cat greeting.txt fruits.txt nums.txt
62
69
Hi there
63
70
Have a nice day
64
71
banana
@@ -142,7 +149,7 @@
142
149
1 2 3^L4^K5
143
150
</code></pre><p>The <code>-v</code> option doesn't cover the newline and tab characters. You can use the <code>-T</code> option to spot tab characters.<pre><codeclass=language-bash>$ printf 'good food\tnice dice\n' | cat -T
144
151
good food^Inice dice
145
-
</code></pre><p>The <code>-E</code> option adds a <code>$</code> marker after the final character of input lines.<pre><codeclass=language-bash>$ printf 'ice \nwater\n cool \n' | cat -E
152
+
</code></pre><p>The <code>-E</code> option adds a <code>$</code> marker at the end of input lines. This is useful to spot invisible trailing characters.<pre><codeclass=language-bash>$ printf 'ice \nwater\n cool \n' | cat -E
</code></pre><blockquote><p><imgsrc=./images/info.svgalt=info> Use the <code>rev</code> command if you want each input line to be reversed character wise.</blockquote></main><navclass=nav-wrapperaria-label="Page navigation"><arel=prevhref=preface.htmlclass="mobile-nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left><iclass="fa fa-angle-left"></i></a><divstyle="clear: both"></div></nav></div></div><navclass=nav-wide-wrapperaria-label="Page navigation"><arel=prevhref=preface.htmlclass="nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left><iclass="fa fa-angle-left"></i></a></nav></div><script>
231
+
</code></pre><blockquote><p><imgsrc=./images/info.svgalt=info> Use the <code>rev</code> command if you want each input line to be reversed character wise.</blockquote></main><navclass=nav-wrapperaria-label="Page navigation"><arel=prevhref=preface.htmlclass="mobile-nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left><iclass="fa fa-angle-left"></i></a><arel=nexthref=head-tail.htmlclass="mobile-nav-chapters next"title="Next chapter"aria-label="Next chapter"aria-keyshortcuts=Right><iclass="fa fa-angle-right"></i></a><divstyle="clear: both"></div></nav></div></div><navclass=nav-wide-wrapperaria-label="Page navigation"><arel=prevhref=preface.htmlclass="nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left><iclass="fa fa-angle-left"></i></a><arel=nexthref=head-tail.htmlclass="nav-chapters next"title="Next chapter"aria-label="Next chapter"aria-keyshortcuts=Right><iclass="fa fa-angle-right"></i></a></nav></div><script>
0 commit comments