This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
os_cp:redirects_pipes [2023/03/23 21:33] jkonczak [Printing file contents] |
os_cp:redirects_pipes [2024/03/19 23:33] (current) jkonczak [Pipes] |
||
---|---|---|---|
Line 7: | Line 7: | ||
Name comes from //con__cat__enate//. \\ | Name comes from //con__cat__enate//. \\ | ||
''cat'' numbers lines with the ''-n'' switch and outputs non-printable characters | ''cat'' numbers lines with the ''-n'' switch and outputs non-printable characters | ||
- | as ''^//x//'', ''M-//x//'', … with the ''-v'' switch. | + | as ''^//x//'', ''M-//x//'', … with the ''-v'' switch((This notation corresponds to keys one would have to press to input the byte. To see all bytes (''\t'' and ''\n'' is replaced by ''X''), try: \\ ''perl -e'for(0..15){printf"\t%x_",$_};print"\n";for$l(0..15){printf"_%x",$l;for$h(0..15){$c=$h<<4|$l;$c=88 if $c==9||$c==10;printf("\t%c",$c)}print"\n"}'|cat -v'')). |
''**paste** //file_1// [//file2//]...'' reads round-robin one line from each input | ''**paste** //file_1// [//file2//]...'' reads round-robin one line from each input | ||
Line 25: | Line 25: | ||
''**od** [-t x1]'', ''**hexdump** [-C]'', and ''**xxd**'' show binary files. | ''**od** [-t x1]'', ''**hexdump** [-C]'', and ''**xxd**'' show binary files. | ||
</small> | </small> | ||
+ | |||
+ | ++++ Examples | {{page>so:redirects:cat&inline}} ++++ | ||
~~Exercise.#~~ Print any file with ''cat''. Print two files at once with ''cat''. \\ | ~~Exercise.#~~ Print any file with ''cat''. Print two files at once with ''cat''. \\ | ||
Line 52: | Line 54: | ||
''**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> | ||
+ | |||
+ | ++++ 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 ''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> | ||
Line 69: | Line 73: | ||
\\ | \\ | ||
With the ''-w'' switch, ''seq'' makes all number of equal width (e.g., ''seq -w 8 11'' outputs 08, 09, 10 and 11). | With the ''-w'' switch, ''seq'' makes all number of equal width (e.g., ''seq -w 8 11'' outputs 08, 09, 10 and 11). | ||
+ | |||
+ | ++++ Examples | {{page>so:redirects:seq&inline}} ++++ | ||
~~Exercise.#~~ Generate a sequence of numbers from 1 to 15. | ~~Exercise.#~~ Generate a sequence of numbers from 1 to 15. | ||
Line 214: | Line 220: | ||
| ''>>'' | opens //word// for appending and replaces //file_number// with the file | | | ''>>'' | opens //word// for appending and replaces //file_number// with the file | | ||
| ''<>'' | opens //word// for reading and writing and replaces //file_number// with the file | | | ''<>'' | opens //word// for reading and writing and replaces //file_number// with the file | | ||
- | | ''<<'' | 1) creates a temporary file \\ 2) reads an input line \\ 3) if the line is //word//, go to step 6 \\ 4) if there are no quotes (a pair of ''"'' or <html><code>'</code></html>) in //word//, performs the expansion((E.g., ''$VAR'' is substituted with its value, ''`date`'' is replaced by output of the date command etc.)) on the line \\ 5) writes the line to the temporary file \\ 6) opens the temporary file for reading \\ 7) replace //file_number// with the file \\ The command is run once this is done | | + | | ''<<'' | 1) creates a temporary file \\ 2) reads an input line \\ 3) if the line is //word//, goes to step 7 \\ 4) if there are no quotes (a pair of ''"'' or <html><code>'</code></html>) enclosing the //word//, performs the expansion((E.g., ''$VAR'' is substituted with its value, ''`date`'' is replaced by output of the date command etc.)) on the line \\ 5) appends the line to the temporary file \\ 6) goes to step 2 \\ 7) opens the temporary file for reading \\ 8) replace //file_number// with the file \\ The command is run once this is done | |
| ''<<-''| same as ''<<'', but after step 2 adds a step: \\ 2a) erase all leading tab characters (''\t'') \\ warning: spaces are not erased | | | ''<<-''| same as ''<<'', but after step 2 adds a step: \\ 2a) erase all leading tab characters (''\t'') \\ warning: spaces are not erased | | ||
| ''<<<''| warning: this is a Bash extension \\ 1) creates a temporary file \\ 2) writes //word// to it \\ 3) writes a newline to it \\ 4) opens the temporary file for reading \\ 5) replace //file_number// with the file \\ The command is run once this is done | | | ''<<<''| warning: this is a Bash extension \\ 1) creates a temporary file \\ 2) writes //word// to it \\ 3) writes a newline to it \\ 4) opens the temporary file for reading \\ 5) replace //file_number// with the file \\ The command is run once this is done | | ||
- | | ''<&'' | if //word// is a number: duplicates a readable descriptor number //word// to the number //file_number// \\ if //word/// is ''-'': closes a descriptor number //file_number// | | + | | ''<&'' | if //word// is a number: duplicates a readable descriptor number //word// to the number //file_number// \\ if //word// is ''-'': closes a descriptor number //file_number// | |
- | | ''>&'' | if //word// is a number: duplicates a writeable descriptor number //word// to the number //file_number// \\ if //word/// is ''-'': closes a descriptor number //file_number// | | + | | ''>&'' | if //word// is a number: duplicates a writeable descriptor number //word// to the number //file_number// \\ if //word// is ''-'': closes a descriptor number //file_number// | |
| ''&>'' | warning: this is a Bash extension \\ warning: this does not allow providing //file_number// (in fact, ''&'' is the file number) \\ opens //word// for writing, truncates it and replaces streams 1 and 2 with the file | | | ''&>'' | warning: this is a Bash extension \\ warning: this does not allow providing //file_number// (in fact, ''&'' is the file number) \\ opens //word// for writing, truncates it and replaces streams 1 and 2 with the file | | ||
| ''&>>''| warning: this is a Bash extension \\ warning: this does not allow providing //file_number// (in fact, ''&'' is the file number) \\ opens //word// for appending and replaces streams 1 and 2 with the file | | | ''&>>''| warning: this is a Bash extension \\ warning: this does not allow providing //file_number// (in fact, ''&'' is the file number) \\ opens //word// for appending and replaces streams 1 and 2 with the file | | ||
Line 234: | Line 240: | ||
standard output (unless you dare to face the consequences). | standard output (unless you dare to face the consequences). | ||
- | ~~Exercise.#~~ Swap standard input with standard output of the | + | ~~Exercise.#~~ Swap standard error with standard output of the |
''cat /etc/motd /etc/shadow'' command. Test if you did this correctly by adding | ''cat /etc/motd /etc/shadow'' command. Test if you did this correctly by adding | ||
''|rev'' at the end (that will put standard output backwards). | ''|rev'' at the end (that will put standard output backwards). | ||
Line 324: | Line 330: | ||
~~Exercise.#~~ Create a named pipe //p//. Redirect input of ''fold'' from //p// | ~~Exercise.#~~ Create a named pipe //p//. Redirect input of ''fold'' from //p// | ||
in one terminal, and redirect output of ''ps -eF'' to //p// in another terminal. | in one terminal, and redirect output of ''ps -eF'' to //p// in another terminal. | ||
- | \\ Then repeat the commands, running the''ps'' before the ''fold''. | + | \\ Then repeat the commands, running the ''ps'' before the ''fold''. |
</small> | </small> | ||
Line 406: | Line 412: | ||
bytes (''-b //spec//'') / fields (''-f //spec//'') in each line. | bytes (''-b //spec//'') / fields (''-f //spec//'') in each line. | ||
\\ | \\ | ||
- | A filed is any number of characters separated by a single-character | + | A field is any number of characters separated by a single-character |
delimiter (''-d //delim//'', defaults to tab). | delimiter (''-d //delim//'', defaults to tab). | ||