extract 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #! /bin/sh
  2. set -e
  3. PREFIX=$1
  4. shift
  5. trap 'rm -r $TMPDIR' 0
  6. TMPDIR=`mktemp -d`
  7. exec 3>/dev/null
  8. for f; do
  9. while IFS="
  10. " read -r LINE; do
  11. case "$LINE" in
  12. *$PREFIX:[0-9]*:\**)
  13. NUM=`echo "$LINE" | sed "s/.*$PREFIX:\([0-9]*\).*/\1/"`
  14. if [ -f $TMPDIR/$NUM ]; then
  15. echo "$TMPDIR/$NUM already exits prior to $f"
  16. exit 1
  17. fi
  18. exec 3>>$TMPDIR/$NUM
  19. echo $f | sed 's,\.\./,,g' > $TMPDIR/.$NUM
  20. /bin/echo "$LINE" | sed -e "s/$PREFIX:[0-9]*//" -e "s/:\*/*/" >&3
  21. ;;
  22. *$PREFIX:[0-9]*)
  23. NUM=`echo "$LINE" | sed "s/.*$PREFIX:\([0-9]*\).*/\1/"`
  24. if [ -f $TMPDIR/$NUM ]; then
  25. echo "$TMPDIR/$NUM already exits prior to $f"
  26. exit 1
  27. fi
  28. exec 3>>$TMPDIR/$NUM
  29. echo $f | sed 's,\.\./,,g' > $TMPDIR/.$NUM
  30. /bin/echo "$LINE" | sed "s/$PREFIX:[0-9]*//" >&3
  31. ;;
  32. *:\**)
  33. /bin/echo "$LINE" | sed -e "s/:\*/*/" -e "s,/\*\*/,," >&3
  34. echo >&3
  35. exec 3>/dev/null
  36. ;;
  37. *)
  38. /bin/echo "$LINE" >&3
  39. ;;
  40. esac
  41. done < $f
  42. echo >&3
  43. exec 3>/dev/null
  44. done
  45. LASTFILE=""
  46. for f in $TMPDIR/*; do
  47. if [ "$LASTFILE" != $(cat $TMPDIR/.$(basename $f) ) ]; then
  48. LASTFILE=$(cat $TMPDIR/.$(basename $f) )
  49. echo "[ $LASTFILE ]"
  50. fi
  51. cat $f
  52. done