= Filtering = Latest change: Mon Sep 19 00:47:12 CEST 2016 Created: Mon Sep 19 00:42:23 CEST 2016 = Motivation = every so often we enter the current date into our texts: 2016-09-19 vim allows to create an abbreviation using strftime: dddd -> 2016-09-19 we can also read it in via a shell and calling "date": :r!date +\%F 2016-09-19 or we replace the current line with "date"'s output: !!date +\%F -> :.!date +\%F 2016-09-19 = Definition = filtering := "input is replaced by output" more precisely: "all input lines are replaced by the output of an external command which can be found be the shell." = Special Cases = "no output" some programs do not produce any output. in that case all input lines are deleted. "input ignored" some programs do not care about the input - such as "date" - and simply yield the same kind of output. = Filters = real filters *require* some input. they cannot be used as a starting point in a chain of commands. example: "tr" the "tr" command "translates" all characters ("letters") from one alphabet into another alphabet of the same length. input alphabet: abcdefghijklmnopqrstuvwxyz output alphabet: nopqrstuvwxyzabcdefghijklm so, reading from left to right, 'a' is replaced by 'n', then 'b' with 'o'.. and so on until 'z' is replaced by 'm'. this very special case of shifting the alphabet of 26 characters "halfway around" by 13 characters is called "rotate 13" or "rot13" for short. when you apply is twice to the same text then the result is the same as before. this operation is "inverse" to itself. = TODO = more filters: * fmt and par * shuf (shuffle) -> ls | nl | shuf * fortune * cowsay * xxd * rev, tac $ vim /etc/passwd :%!column -s: -t -n vim: set et ft=sven tw=999 nowrap: THPXRF EOF