User Tools

Site Tools


os_cp:redirects_pipes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
os_cp:redirects_pipes [2025/03/26 15:44]
jkonczak
os_cp:redirects_pipes [2026/03/24 14:33] (current)
jkonczak [more, less]
Line 46: Line 46:
 ==== Printing text ==== ==== Printing text ====
  
-''​**echo** //​text//''​ outputs //text// followed by a newline ​(unless ​''​-n''​ is specified). \\ +''​**echo** //​text//''​ outputs //text// followed by a newline. \\ 
-The ''​-e''​ switch turns backslash escapes into corresponding characters, e.g., ''​\t''​ +<​small>​ 
-becomes a tab and ''​\n''​ a newline (cf. manual).+''​echo''​ is present in almost any shell of any operating system, 
 +but there is no consensus on how to interpret switches and how to treat 
 +backslashes in the text. 
 +\\ 
 +In Bash, the  ​''​-n''​ switch ​supresses the newline, and ''​-e'' ​turns backslash 
 +escapes into corresponding characters, e.g., ''​\t''​ becomes a tab and ''​\n''​ 
 +a newline (cf. manual). 
 +</​small>​
  
 ''​**printf** //format// [//​arguments//​]...''​ works roughly the same as the ''​printf''​ function in C. ''​**printf** //format// [//​arguments//​]...''​ works roughly the same as the ''​printf''​ function in C.
  
 <​small>​ <​small>​
-''​**figlet** [//​text//​]''​ outputs //text// or the standard input by using ascii-art font. +Here and there, the course materials make use of the following toy commands: 
 +\\ 
 +''​**figlet** [//​text//​]''​ outputs //text// or the standard input by using an ascii-art font. 
 +\\
 ''​**cowsay** [//​text//​]''​ makes a cow say the //text// (or the standard input). ''​**cowsay** [//​text//​]''​ makes a cow say the //text// (or the standard input).
 </​small>​ </​small>​
Line 60: Line 69:
 ++++ Examples | {{page>​so:​redirects:​echo&​inline}} ++++ ++++ Examples | {{page>​so:​redirects:​echo&​inline}} ++++
  
-~~Exercise.#​~~ Try ''​echo -e '​foo\n\nbaz'​ ''​ \\ and ''​echo -e '\n\n one \033[A \033[A two \033[B \033[B \n \033[1;31m red \033[0m'​ ''​ \\ <​small>​[[https://​en.wikipedia.org/​wiki/​ANSI_escape_code|ANSI escape codes]] are well summarized [[https://​gist.github.com/​fnky/​458719343aabd01cfb17a3a4f7296797|here]]</​small>​+~~Exercise.#​~~ Try the commands ​''​echo -e '​foo\n\nbaz'​ ''​ \\ and ''​echo -e '\n\n one \033[A \033[A two \033[B \033[B \n \033[1;31m red \033[0m'​ ''​ \\ <​small>​[[https://​en.wikipedia.org/​wiki/​ANSI_escape_code|ANSI escape codes]] are well summarized [[https://​gist.github.com/​fnky/​458719343aabd01cfb17a3a4f7296797|here]]</​small>​
  
 ~~Exercise.#​~~ Try ''​printf "​|%4.2f|%3s|%-20s|\n|%4.2f|%3s|%-20s|\n"​ 3.1428 pi circumference/​radius 9.8 g gravity''​ ~~Exercise.#​~~ Try ''​printf "​|%4.2f|%3s|%-20s|\n|%4.2f|%3s|%-20s|\n"​ 3.1428 pi circumference/​radius 9.8 g gravity''​
Line 173: Line 182:
  
 ~~Exercise.#​~~ Redirect standard output and the standard error of the ''​find /​var/​spool/''​ command to the same file. ~~Exercise.#​~~ Redirect standard output and the standard error of the ''​find /​var/​spool/''​ command to the same file.
 +
 +++++ Examples | {{page>​so:​redirects:​out-en&​inline}} ++++
  
 === Input redirections === === Input redirections ===
Line 201: Line 212:
  
 ~~Exercise.#​~~ Use ''​bc''​ to calculate ''​sqrt(2.0000)''​ in non-interactive mode and redirect its output to a file. ~~Exercise.#​~~ Use ''​bc''​ to calculate ''​sqrt(2.0000)''​ in non-interactive mode and redirect its output to a file.
 +
 +++++ Examples | {{page>​so:​redirects:​in&​inline}} ++++
  
 <​small>​ <​small>​
Line 335: Line 348:
 \\ Then repeat the commands, running the ''​ps''​ before the ''​fold''​. \\ Then repeat the commands, running the ''​ps''​ before the ''​fold''​.
 </​small>​ </​small>​
 +
 +++++ Examples | {{page>​so:​redirects:​pipes1-en&​inline}} ++++
  
 ===== Filters ===== ===== Filters =====
Line 363: Line 378:
 ~~Exercise.#​~~ Run ''​seq 25 > //​file//''​. Then run ''​tail -f //​file//''​ in one ~~Exercise.#​~~ Run ''​seq 25 > //​file//''​. Then run ''​tail -f //​file//''​ in one
 terminal and append (with output redirection) some data to //file//. terminal and append (with output redirection) some data to //file//.
 +
 +++++ Examples | {{page>​so:​pipes_filters:​head_tail&​inline}} ++++
  
 ==== grep ==== ==== grep ====
Line 374: Line 391:
 <​small>​ <​small>​
 The ''​grep''​ program accepts several regular expression grammars. The ''​grep''​ program accepts several regular expression grammars.
-POSIX [[https://​pubs.opengroup.org/​onlinepubs/​9699919799/​basedefs/​V1_chap09.html|specifies]]+POSIX [[https://​pubs.opengroup.org/​onlinepubs/​9799919799/​basedefs/​V1_chap09.html|specifies]]
 basic (default for ''​grep''​) and extended regular expressions (selectable with basic (default for ''​grep''​) and extended regular expressions (selectable with
 ''​egrep''​ or ''​grep -E''​ ). See manual for your implementation of ''​grep''​ for ''​egrep''​ or ''​grep -E''​ ). See manual for your implementation of ''​grep''​ for
Line 409: Line 426:
 \\ \\
 List all files containing ''​ecdsa''​ in ''​~/​.ssh''​. List all files containing ''​ecdsa''​ in ''​~/​.ssh''​.
 +
 +++++ Examples | {{page>​so:​pipes_filters:​grep&​inline}} ++++
  
 ==== cut ==== ==== cut ====
Line 430: Line 449:
 ''​egrep '​^[Ee]{2}'​ /​usr/​share/​myspell/​en_US.dic''​ a slash and all that follows ''​egrep '​^[Ee]{2}'​ /​usr/​share/​myspell/​en_US.dic''​ a slash and all that follows
 it. it.
 +
 +++++ Examples | {{page>​so:​pipes_filters:​cut-en&​inline}} ++++
  
 ==== sort ==== ==== sort ====
Line 474: Line 495:
 ~~Exercise.#​~~ Sort the file by the second column (alphabetically) and by the third column (numerically). ~~Exercise.#​~~ Sort the file by the second column (alphabetically) and by the third column (numerically).
 </​small>​ </​small>​
 +
 +++++ Examples | {{page>​so:​pipes_filters:​sort&​inline}} ++++
  
 ==== wc, uniq, nl ==== ==== wc, uniq, nl ====
Line 506: Line 529:
 \\ \\
 Then pipe it through ''​sort''​ and ''​uniq''​ so that you see how many times each result was hit. Then pipe it through ''​sort''​ and ''​uniq''​ so that you see how many times each result was hit.
 +
 +++++ Examples | {{page>​so:​pipes_filters:​wc_uniq&​inline}} ++++
  
 <​small>​ <​small>​
Line 540: Line 565:
   * to squeeze all spaces   * to squeeze all spaces
   * remove all the letters ''​rwx''​   * remove all the letters ''​rwx''​
 +
 +++++ Examples | {{page>​so:​pipes_filters:​tr-en&​inline}} ++++
  
 <​small>​ <​small>​
Line 582: Line 609:
 not human-readable file format. not human-readable file format.
 \\ \\
-''​[[https:/​/​github.com/​wofr06/​lesspipe|lesspipe]]''​ is the leading implementation+''​[[https://​lesspipe.org|lesspipe]]''​ is the leading implementation
 of this feature. of this feature.
 </​small>​ </​small>​
os_cp/redirects_pipes.1743000284.txt.gz · Last modified: 2025/03/26 15:44 by jkonczak