浏览代码

artificial-ignorance uses first term as filename

George Jones 2 年之前
父节点
当前提交
296cb6239d
共有 1 个文件被更改,包括 27 次插入4 次删除
  1. 27 4
      bin/artificial-ignorance.sh

+ 27 - 4
bin/artificial-ignorance.sh

@@ -8,7 +8,16 @@
 #
 #   Input:
 #      - input-file on the command line
-#      - terms - one or more on the command line
+#      - terms - one or more on the command line.
+#
+#                terms can have "|" to match more than one term.
+#
+#                If there is a "|", the first term will be used
+#                as the output file name.
+#
+#                Note if you want the
+#                output to have a particualr name, use it as
+#                the first term, it may not actually match in grep.
 #
 #   Output:
 #      - ai-TERM1.txt
@@ -16,6 +25,18 @@
 #      - ...
 #      - ai-TERMn.txt
 #      - ai-leftovers.txt
+#
+# Example
+#
+# I wrapped this in a shell script as follows to write a report.
+#
+#    ! /bin/bash
+#    artificial-ignorance.sh completd-only.org \
+#    'research-projects|clustering|heatmaps' \
+#    'external|USENIX' \
+#    'products|firewall' \
+#    'development|lint|make|python' \
+#
 # set -e
 set -u
 
@@ -35,11 +56,13 @@ fi
 
 for var in "$@"
 do
-    OUTPUT="${PREFIX}${var}.txt"
     PATTERN="${var}"
-    LEFTOVERS_TMP="ai-leftovers-${var}.tmp"
+    # allow patterns of A|B|C, use first element as name
+    FIRST_ELEMENT=`echo $PATTERN | sed -e 's/|.*//'`
+    OUTPUT="${PREFIX}${FIRST_ELEMENT}.txt"
+    LEFTOVERS_TMP="ai-leftovers-${FIRST_ELEMENT}.tmp"
 
-    cat $INPUT | tee >(egrep -i $PATTERN > $OUTPUT) | (egrep -vi $PATTERN > $LEFTOVERS_TMP)
+    cat $INPUT | tee >(egrep -i "$PATTERN" > $OUTPUT) | (egrep -vi "$PATTERN" > $LEFTOVERS_TMP)
 
 
     INPUT=$LEFTOVERS_TMP