#!/bin/bash # Program Name: RTF Title Rename # Creation Date: 3/6/2007 # Revision Date: 3/7/2007 # Description: Rename the file to the RTF \title tag. # Ask/test for destination and run cp_awk function title_rename { echo "Enter source directory name (no spaces):" read sdirname if [ ! $sdirname = "" ] && [ -d $sdirname ]; then echo "Enter destination directory name (no spaces):" read dirname if [ ! $dirname = "" ]; then if [ -d $dirname ]; then echo "Directory Exists!" echo echo "Overwrite files? Y or N" read answer if [ $answer = Y ] || [ $answer = y ]; then cp_awk else title_rename fi else mkdir "$dirname" cp_awk fi else echo "You must enter a directory name!" echo title_rename fi else echo "Directory does not exist!" title_rename fi } # Rename all rtf files, based on our awk script parsing function cp_awk { cd $sdirname for i in *.rtf; do cp "$i" ../$dirname/`cat $i | awk -f ../title.awk`; done option_two echo "Title rename process completed." } function enter_prompt { # Pauses the script echo echo -n "Press Enter to go back." read clear } function option_two { clear echo "Thank you for using T.J.'s RTF Title Rename, $USER!" exit } # Display the menu until [ "$selection" = "2" ]; do clear echo -e " \033[5m Title Rename Menu \033[0m" echo echo -e " \033[5m Copyright 2007 T.J. Wood \033[0m" echo echo " 1) Execute Title Rename Script." echo echo " 2) Quit." echo echo " Please enter your choice:" read selection case $selection in 1) echo title_rename ;; 2) option_two;; *) echo "Valid Choices: 1 or 2"; enter_prompt;; esac done