#!/bin/sh # Read .java files in source directory, # copying lines from the first line matching # the start pattern to the end of the file # to a file of the same name in the target directory # # Designed to be used to remove license header and imports from # annotation and enum files in the JDO api project for import # into the FrameMaker specification # # Tested on cygwin and Mac # USAGE="behead " if [ $# -ne 2 ] then echo $USAGE exit -1 fi SRCDIR=$1 TARGETDIR=$2 STARTPATTERN="^@" ENUMSTARTPATTERN="public enum" for FILE in `ls $SRCDIR/*.java` do ROOT=`basename $FILE .java` OUTFILE=${TARGETDIR}/${ROOT}.txt IS_ENUM=0 if [ `grep -c "public enum" $FILE` -gt 0 ] then STARTINDEX=`grep --max-count=1 -n "${ENUMSTARTPATTERN}" $FILE | cut -d: -f1 ` IS_ENUM=1 else STARTINDEX=`grep --max-count=1 -n $STARTPATTERN $FILE | cut -d: -f1 ` IS_ENUM=0 fi #echo $STARTINDEX ENDINDEX=`wc -l $FILE | sed -e "s/^ *//" | cut -f1 -d" " ` #echo $ENDINDEX NUMLINES=`expr $ENDINDEX - $STARTINDEX + 1` echo Copying ${NUMLINES} lines from $FILE to $OUTFILE if [ ${IS_ENUM} -eq 1 ] then # Workaround for Frame bug: Add blank line at beginning tail -n ${NUMLINES} $FILE | sed -e "1H" -e "1g" > ${OUTFILE} else tail -n ${NUMLINES} $FILE > ${OUTFILE} fi done