Skip to content

Instantly share code, notes, and snippets.

@Horopter
Created October 22, 2015 14:20
Show Gist options
  • Save Horopter/fa7a2abe6c1894df63de to your computer and use it in GitHub Desktop.
Save Horopter/fa7a2abe6c1894df63de to your computer and use it in GitHub Desktop.
Merge several files into one for documentation purposes
#!/bin/sh -u
zenity --info --ok-label="Start" --width="500" --height="300" --title="Horopter Inc." --text "`basename $0` is loaded. Click start to continue."
current=`pwd`
zenity --question --width="500" --height="300" --title="Welcome to Horopter fileconverter." --text "You need to put all the required files together in a directory, did you do that?"
if [ $? -eq 0 ]
then
zenity --info --width="500" --height="300" --title="Horopter Inc." --text "Example: If the files are in a directory called 'apple',\n /folder1/folder2/apple is location into the directory apple."
path=$(zenity --entry --width="500" --height="300" --title="Directory selection" --text "Enter the location into the directory as absolute path, . for current directory: ")
if [ -n "$path" ]
then
cd $path
flname=$(zenity --entry --width="500" --height="300" --title="Directory selection" --text "Enter the name of the output file with extension.")
echo -e "******************************* $flname ******************************\n" > $flname
echo -e "------------ Compiled by a software from SANTOSH KUMAR DESAI ------------\n" >> $flname
echo -e "<< This is preformatted text >>" >> $flname
declare -a var
var=(*.html *.css *.txt)
count=0
for i in "${var[@]}"
do
input=`echo $i | cut -d '.' -f1`
if [ "$input" != "*" ]
then
let count=count+1
fi
done
zenity --info --title="Horopter Inc." --width="500" --height="300" --text "Total $count files were found."
cnt=1
( for i in "${var[@]}"
do
input=`echo $i | cut -d '.' -f1`
if [ "$input" != "*" ]
then
echo -e "# copying $i ($cnt of $count)"; sleep 1
echo -e "--------DOCUMENT $i STARTS HERE--------\n" >> $flname
cat $i >> $flname
echo -e "\n--------DOCUMENT $i ENDS HERE-----------\n\n\n" >> $flname
echo -e "# copying $i complete. ($cnt of $count)" ; sleep 1
sed '/^$/d' $flname
echo `expr $cnt \* 100 / $count - 10`; sleep 1
let cnt=cnt+1
fi
done
echo -e "# Finishing the job"; sleep 1
echo -e "\n**************************** END OF DOCUMENT ****************************" >> $flname
echo -e "\nAll files were merged through a shell script from SANTOSH KUMAR DESAI " >> $flname
echo -e "# Total $count files were copied."; sleep 1
echo -e "# Compiling all the files into one file is complete.\n"; sleep 1
echo "100" ; sleep 1
)| zenity --progress --width="500" --height="300" \
--title="Merging the files..." \
--text="Starting progress now..." \
--percentage=0
zenity --info --title="Horopter Inc." --width="500" --height="300" --text "The file is named $flname and it will be available in the same directory as other merged files. \n Thanks for using this shell script ---- Horopter."
fi
fi
cd $current
zenity --info --title="Horopter Inc." --ok-label="Finish" --width="500" --height="300" --text "Click finish to exit."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment