]> git.plutz.net Git - confetti/blobdiff - pdiread.sh
tidy up
[confetti] / pdiread.sh
index 8118318d3d4bdd4e2793d468c037b28b5006588f..08fbaec3fb373c2fbb6cdde7974caaa520b849e3 100755 (executable)
@@ -26,13 +26,23 @@ include_pdi="$0"
 BR='
 '
 
+unescape() {
+  local unescape='s;(^(\\\\)*|[^\\](\\\\)*)\\n;\1\n;g; s;\\(.);\1;g'
+  if [ $# -eq 0 ]; then
+    sed -E "$unescape"
+  else
+    printf %s "$*" \
+    | sed -E "$unescape"
+  fi
+}
+
 pdi_load() {
   # normalise PDI file for processing with pdi_* functions
   # functions in this library can only be applied to normalised data
   # Usage example:
   # data="$(pdi_load file.vcf)"
 
-  sed -En '
+  sed -srn '
     # === Read entire file into buffer ===
     :X $bY; N; bX; :Y s;^.*$;\n&\n;;
 
@@ -100,7 +110,7 @@ pdi_load() {
     # === Update obsolete LABEL property ===
     s;\nLABEL((\;[A-Za-z0-9-]+|\;[A-Za-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)\n;\nADR\1\;LABEL="\5":\n;g;
 
-    p;' "$1"
+    p;' "$@"
 }
 
 pdi_count(){