From c07a5a71e2aedd0318ab34be1f0c7ac28de101fb Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sat, 8 Dec 2018 21:44:50 -0500 Subject: [PATCH] close https://github.com/johnkerl/miller/issues/203 --- doc/content-for-faq.html | 14 ++++++++++++++ doc/data/question.dat | 1 + doc/faq.html | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 doc/data/question.dat diff --git a/doc/content-for-faq.html b/doc/content-for-faq.html index b76dc6e5b..03c9cfe52 100644 --- a/doc/content-for-faq.html +++ b/doc/content-for-faq.html @@ -154,6 +154,20 @@ POKI_RUN_COMMAND{{echo x,y,z | mlr --csv --implicit-csv-header reorder -f 3,1,2} POKI_RUN_COMMAND{{echo 'x.a=3,y:b=4,z/c=5' | mlr put '${product.all} = ${x.a} * ${y:b} * ${z/c}'}}HERE + +

How to escape '?' in regexes?

+ +
+ +

One way is to use square brackets; an alternative is to use simple +string-substitution rather than a regular expression. + +POKI_RUN_COMMAND{{cat data/question.dat}}HERE +POKI_RUN_COMMAND{{mlr --oxtab put '$c = gsub($a, "[?]"," ...")' data/question.dat}}HERE +POKI_RUN_COMMAND{{mlr --oxtab put '$c = ssub($a, "?"," ...")' data/question.dat}}HERE + +

The ssub function exists precisely for this reason: so you don’t have to escape anything. +

How can I put single-quotes into strings?

diff --git a/doc/data/question.dat b/doc/data/question.dat new file mode 100644 index 000000000..d40b0adfd --- /dev/null +++ b/doc/data/question.dat @@ -0,0 +1 @@ +a=is it?,b=it is! diff --git a/doc/faq.html b/doc/faq.html index 719d1397e..01ef07209 100644 --- a/doc/faq.html +++ b/doc/faq.html @@ -195,6 +195,7 @@ Miller commands were run with pretty-print-tabular output format. • How do I examine then-chaining?
• I assigned $9 and it’s not 9th
• How can I handle field names with special symbols in them?
+• How to escape '?' in regexes?
• How can I put single-quotes into strings?
• Why doesn’t mlr cut put fields in the order I want?
• NR is not consecutive after then-chaining
@@ -596,6 +597,45 @@ x.a=3,y:b=4,z/c=5,product.all=60

+ +

How to escape '?' in regexes?

+ +
+ +

One way is to use square brackets; an alternative is to use simple +string-substitution rather than a regular expression. + +

+

+
+$ cat data/question.dat
+a=is it?,b=it is!
+
+
+

+

+

+
+$ mlr --oxtab put '$c = gsub($a, "[?]"," ...")' data/question.dat
+a is it?
+b it is!
+c is it ...
+
+
+

+

+

+
+$ mlr --oxtab put '$c = ssub($a, "?"," ...")' data/question.dat
+a is it?
+b it is!
+c is it ...
+
+
+

+ +

The ssub function exists precisely for this reason: so you don’t have to escape anything. +

How can I put single-quotes into strings?