aboutsummaryrefslogtreecommitdiffstats
path: root/TRICKS.md
diff options
context:
space:
mode:
Diffstat (limited to 'TRICKS.md')
-rw-r--r--TRICKS.md45
1 files changed, 45 insertions, 0 deletions
diff --git a/TRICKS.md b/TRICKS.md
new file mode 100644
index 0000000..b14e002
--- /dev/null
+++ b/TRICKS.md
@@ -0,0 +1,45 @@
+
+## Using a text editor
+
+You can enter the ANSI control characters in terminals and many text editors
+using "Ctrl-V" escape syntax. For example, to enter the Record Separator
+character on a US-style keyboard: while holding the "Ctrl" and "Shift" keys
+down, press first "v" and then "6" ("^" is Shift-6). You may be able to get
+away with only holding the "Ctrl" modifier and not "Shift". Your editor should
+display this "non-printable" character somehow; a common terminal pattern is to
+print it as `^^` in a different color.
+
+You may be familiar with this from characters like Carriage Return, which
+displays as `^M` and can be entered "Ctrl-V, Ctrl-M".
+
+
+## Simple conversion with UNIX commands
+
+For simple tables, which can be represented in TSV with with no escaping (eg,
+no tab, newline, or ANSI characters in fields), we can transform between AFT
+and TSV pretty easily.
+
+From AFT to TSV with `tr` (retaining all header columns):
+
+ cat examples/days.aft | tr -d "\001\002\035" | tr "\036\037" "\t;" | cat -v
+
+From TSV to AFT with `tr` and `sed`:
+
+ echo -n $'\001' > out.aft
+ head -n1 examples/days.tsv | tr "\t" "\036" | sed 's/$/\x1D/g' >> out.aft
+ echo -n $'\002' >> out.aft
+ tail -n +2 examples/days.tsv | tr "\t;" "\036\037" | sed 's/$/\x1D/g' >> out.aft
+ cat -v out.aft
+
+It is probably possible to do this with a single `awk` command as well.
+
+
+## Working with UNIX commands
+
+You can pass input and output delimiter characters to `cut`:
+
+ cut -f1,2 -d $'\036' --output-delimiter $'\t' examples/days.aft
+
+With `awk` you can specify "field separators", for both input and output:
+
+ awk 'BEGIN { FS="\036"; OFS="\t"; RS="\035\n" } {print $1 $3}' examples/days.aft