This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 2nd, 2012  |  syntax: Bash  |  size: 1.16 KB  |  views: 42  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2. # init
  3.  
  4. echo "Enter current date string (YYYY-MM-DD)."
  5. read date
  6.  
  7. ## mount -t smbfs //"$USER"@server/sharename /mountdir
  8.  
  9. while read -r -d $'\0\'' dir    ##Outer loop for directories
  10. do
  11.         echo "Processing $dir"
  12.         n=0                     ##Reset file counter
  13.         while read -d $'\0' f   ##Inner loop for files
  14.         do
  15.  
  16.  
  17. ## NOTE: THE BELOW SHOULD BE DONE ONLY IF THERE ARE MORE THAN ONE FILE IN THE DIRECTORY
  18.                 if (( n==0 ))
  19.                 then
  20.                         sed -i '/<Footer>/,/<\/Footer>/d' $f
  21.                         sed -i '/<\/ACES>/d' $f
  22.                 else
  23.                         sed -i '/<?xml version="1.0" encoding="iso-8859-1"?>/d' $f
  24.                         sed -i '/<ACES version="3.0">/d' $f
  25.                         sed -i '/<Header>/,/<\/Header>/d' $f
  26.                         sed -i '/<Footer>/,/<\/Footer>/d' $f
  27.                         sed -i '/<\/ACES>/d' $f
  28.                 fi
  29. ## END NOTE
  30.  
  31.  
  32.  
  33.         (( n++ ))
  34.         done  < <( find "$dir" -maxdepth 1 -mindepth 1 -type f -print0 | sort -z )
  35. done < <( find -maxdepth 1 -mindepth 1 -type d l-print0 | sort -z)
  36.  
  37. mkdir ../JOINED
  38.  
  39. ## ## NOTE: THE BELOW SHOULD BE DONE ONLY IF THERE ARE MORE THAN ONE FILE IN THE DIRECTORY
  40. for DIR in *; do
  41.         [ -d "$DIR" ] && cat "$DIR"/*.xml > ../JOINED/"$DIR"_"$date.xml"
  42. done
  43. ## END NOTE
  44.  
  45.  
  46.  
  47.  
  48. cd ../JOINED
  49. find -name '*.xml' -size 0 -delete
clone this paste RAW Paste Data