Guest User

Verfying file names conforming to naming convention

a guest
Dec 13th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.21 KB | None | 0 0
  1. ## Written by Julian Rutledge, February 2012.
  2. ## Licensed for use under the GPL v3
  3.  
  4.  
  5. #!/bin/sh
  6.  
  7.  
  8.  
  9. #establish working directory and make subdirectory to contain batchfiles
  10.  
  11. echo "enter path to directory to be scanned"
  12.  
  13. read DIR
  14.  
  15.  
  16.  
  17. PWD=`pwd`
  18.  
  19. mkdir $PWD/batchfiles.d
  20.  
  21.  
  22.  
  23. #make file list
  24.  
  25. ls $DIR | cat -n > $PWD/batchfiles.d/filelist-total.txt
  26.  
  27.  
  28.  
  29. #create error log
  30.  
  31. touch $PWD/batchfiles.d/fnc.errorlist
  32.  
  33.  
  34.  
  35. #create first list of unscanned files and populate from list of files to be scanned
  36.  
  37. cat $PWD/batchfiles.d/filelist-total.txt > $PWD/batchfiles.d/filelist-work.txt
  38.  
  39.  
  40.  
  41. #set total number of files to be scanned as the first field of last line from the total list
  42.  
  43. TOTALNUM=`cat $PWD/batchfiles.d/filelist-total.txt | tail -n1 | cut -f1`
  44.  
  45.  
  46.  
  47. #initialize cut number variable as total number of files to be scanned
  48.  
  49. CUTNUM=$TOTALNUM
  50.  
  51.  
  52.  
  53. while [ $CUTNUM -gt 0 ]; do
  54.  
  55.     #grab first line from working list
  56.  
  57.     FIRSTLINE=`cat $PWD/batchfiles.d/filelist-work.txt | head -n1`
  58.  
  59.     #set file number number as the first field of first line of the working list
  60.  
  61.     FILENUM=`cat $PWD/batchfiles.d/filelist-work.txt | head -n1 | cut -f1`
  62.  
  63.     #set sort field as the fourth field of the first line (delimited by periods) of the working list
  64.  
  65.     SORTFIELD=`cat $PWD/batchfiles.d/filelist-work.txt | head -n1 | cut -d. -f4`
  66.  
  67.     # search for period as delimiter in file
  68.  
  69.     DLIM=`echo $FIRSTLINE | grep "\."`
  70.  
  71.     #if there is no delimter, wipe the sortfield variable
  72.  
  73.     if [ "$DLIM" = "" ]; then
  74.  
  75.         SORTFIELD=""
  76.  
  77.     fi
  78.  
  79.     #if the sortfield variable is empty, print the filename to the error log, otherwise continue scanning
  80.  
  81.     if [ "$SORTFIELD" = "" ]; then
  82.  
  83.         CUTNUM=$(($TOTALNUM - $FILENUM))
  84.  
  85.         tail -n$CUTNUM $PWD/batchfiles.d/filelist-total.txt > $PWD/batchfiles.d/filelist-work.txt
  86.  
  87.         echo $FIRSTLINE >> $PWD/batchfiles.d/fnc.errorlist
  88.  
  89.     else
  90.  
  91.         CUTNUM=$(($TOTALNUM - $FILENUM))
  92.  
  93.         tail -n$CUTNUM $PWD/batchfiles.d/filelist-total.txt > $PWD/batchfiles.d/filelist-work.txt
  94.  
  95.     fi
  96.  
  97. done
  98.  
  99.  
  100.  
  101. #print errorlist to stdout
  102.  
  103. cat $PWD/batchfiles.d/fnc.errorlist
  104.  
  105.  
  106.  
  107. #clean up temp files
  108.  
  109. rm -r $PWD/batchfiles.d
Advertisement
Add Comment
Please, Sign In to add comment