All pastes #391813 Raw Edit

Mine

public text v1 · immutable
·published 2007-03-12 12:33 UTC
rendered paste body
#!/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 sdir
        if [ ! $sdir = "" ] && [ -d $sdir ]; then
                        echo "Enter destination directory name (no spaces):"
                        read dname
                        if [ ! $dname = "" ]; then
                                if [ -d $dname ]; then
                                echo "Directory Exists!"
                                echo
                                echo "Overwrite files? Y or N"
                                read answer
                                if [ $answer = Y ] || [ $answer = y ]; then
                                        echo $dname > dname.tmp
                                        cp_awk
                                else
                                        title_rename
                                fi
                        else
                                mkdir "$dname"
                                echo $dname > dname.tmp
                                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
{
        find ./$sdir/* > findtree.tmp
        awk -f tree2cmd.awk findtree.tmp > cpawk.sh
        sh cpawk.sh
        echo "Title rename process completed."
        enter_prompt
        rm cpawk.sh
        rm findtree.tmp
        rm dname.tmp
}

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

____________________________________________________________________________________


function mid()
{
        dir = $i "/";
        cpa = cpa dir;
        cpb = cpb dir;
}
BEGIN {
        FS = "[/]";
        print "#!/bin/bash";
        print "dname=`cat ./dname.tmp`;";
}
/[A-Za-z0-9]+\.rtf/ {
        for (i = 1; i <=NF; i++) {
                if (i == 1) {
                source = $i "/";
                cpa = source;
                dest = $i "/$dname/";
                cpb = dest;
                }
                else if (i < (NF-1)) {
                mid()
                }
                else if (i == (NF-1)) {
                mid();
                tree = cpb;
                }
                else {
                filea = $i;
                cpa = cpa filea;
                fileb = "`cat " cpa " | awk -f ./title.awk`;";
                cpb = cpb fileb;
                }
        }
        print "mkdir -p " tree;
        print "cp " cpa, cpb;

____________________________________________________________________________________


BEGIN {
        FS = "[{}]"
}
/\\title/ {
        gsub(/\\title /,"")
        gsub(/\\'97/,"_")
        gsub(/\\`97/,"_")
        gsub(/[ \\\/,'`]/,"_")
#       gsub(/\\/,"")
#       gsub(/`/,"")
#       gsub(/,/,"_")
#       gsub(/'/,"")
#       gsub(/[0-9]/,"")
        print $5".rtf"