Browse Source

simplify awk script

Daniel Sheffield 1 year ago
parent
commit
c7bab25825
1 changed files with 10 additions and 16 deletions
  1. 10 16
      update-evolution-mail-list.sh

+ 10 - 16
update-evolution-mail-list.sh

@@ -44,26 +44,20 @@ EOF
 )
 
     vcard=$(awk \
-        -v new_email="EMAIL;X-EVOLUTION-DEST-HTML-MAIL=FALSE;X-EVOLUTION-PARENT-UID=0:$contact_email" \
-        -v max_width=75 '
-BEGIN { FS=":"; OFS=":"; found=0 }
+      -v new_email="EMAIL;X-EVOLUTION-DEST-HTML-MAIL=FALSE;X-EVOLUTION-PARENT-UID=0:$contact_email" \
+      -v max_width=75 '
+BEGIN { FS=":"; OFS=":" }
 /BEGIN:VCARD/ { print $0; p=1; next }
 /END:VCARD/ {
-  buffer = buffer $0 ORS
-  p = 0
-}
-p
-END {
-  if (found == 0) {
-    wrapped_email = new_email
-    while (length(wrapped_email) > max_width) {
-      print substr(wrapped_email, 1, max_width)
-      wrapped_email = " " substr(wrapped_email, max_width + 1)
-    }
-    print wrapped_email
+  while (length(new_email) > max_width) {
+    print substr(new_email, 1, max_width)
+    new_email = " " substr(new_email, max_width + 1)
   }
-  print buffer
+  print new_email
+  print $0
+  next
 }
+p
 ' <<< "$vcard")
     #read -p "$vcard"
     vcard=$(awk '{printf "%s\\n", $0}' <<< "$vcard")