Add fixeeprom and fixtelem to rename files with correct flight numbers
authorKeith Packard <keithp@keithp.com>
Sun, 22 Nov 2009 08:24:33 +0000 (00:24 -0800)
committerKeith Packard <keithp@keithp.com>
Sun, 22 Nov 2009 08:24:33 +0000 (00:24 -0800)
fixeeprom [new file with mode: 0755]
fixtelem [new file with mode: 0755]

diff --git a/fixeeprom b/fixeeprom
new file mode 100755 (executable)
index 0000000..34e8ac3
--- /dev/null
+++ b/fixeeprom
@@ -0,0 +1,21 @@
+#!/bin/sh
+for i in "$@"; do
+    num=`grep '^F' "$i" | awk '{printf ("%03d\n", strtonum("0x" $4))}'`
+    newname=`echo "$i" | sed 's/flight-[0-9][0-9][0-9]/flight-'"$num"'/'`
+    echo $num "$i" "$newname"
+done | sort -rn | sed 's/^[0-9][0-9]*//' | while read old new; do
+    if [ $new = $old ]; then
+       :
+    else
+       if [ -f $new ]; then
+           if cmp $new $old; then
+               echo "$old is a duplicate of $new"
+               rm $old
+           else
+               echo "$old: $new already exists"
+           fi
+       else
+           mv $old $new
+       fi
+    fi
+done
\ No newline at end of file
diff --git a/fixtelem b/fixtelem
new file mode 100755 (executable)
index 0000000..c0572ca
--- /dev/null
+++ b/fixtelem
@@ -0,0 +1,27 @@
+#!/bin/sh
+for i in "$@"; do
+    if grep -q FLIGHT $i; then
+       num=`head -1 $i | awk '{ for (i = 0; i < NF; i++)
+                  if ($i == "FLIGHT")
+              printf ("%03d\n", $(i+1)); }'`
+    else
+       num=`echo "$i" | sed 's/^.*flight-//' | sed 's/\..*$//'`
+    fi
+    newname=`echo "$i" | sed 's/flight-[0-9][0-9][0-9]/flight-'"$num"'/'`
+    echo $num "$i" "$newname"
+done | sort -rn | sed 's/^[0-9][0-9]*//' | while read old new; do
+    if [ $new = $old ]; then
+       : echo correct: $old
+    else
+       if [ -f $new ]; then
+           if cmp $new $old; then
+               echo "$old is a duplicate of $new"
+               echo rm $old
+           else
+               echo "$old: $new already exists"
+           fi
+       else
+           echo mv $old $new
+       fi
+    fi
+done
\ No newline at end of file