aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TRICKS.md45
-rw-r--r--examples/days.aft9
-rw-r--r--examples/days.tsv8
3 files changed, 62 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
diff --git a/examples/days.aft b/examples/days.aft
new file mode 100644
index 0000000..44095ca
--- /dev/null
+++ b/examples/days.aft
@@ -0,0 +1,9 @@
+ordername星期几
+integerstringstring
+1Monday星期一
+2Tuesday星期二
+3Wednesday星期三
+4Thursday星期四
+5Friday星期五
+6Saturday星期六
+7Sunday星期天
diff --git a/examples/days.tsv b/examples/days.tsv
new file mode 100644
index 0000000..8ce1d98
--- /dev/null
+++ b/examples/days.tsv
@@ -0,0 +1,8 @@
+order name
+1 Sunday
+2 Monday
+3 Tuesday
+4 Wednesday
+5 Thursday
+6 Friday
+7 Saturday