Tuesday, November 25, 2014

filemerger.sh


This is a software I developed, merges several files into one.

#!/bin/sh -u 
echo -e "$0 is loaded."
echo -e "You need to put all the required files together in a directory, press Y if yes, N if no"
read choice
if [ "$choice" = "y" -o "$choice" == "Y" ]
then 
 echo -e "Example: If the files are in a directory called 'apple', /folder1/folder2/apple is location into the directory apple."
 echo -e "Enter the location into the directory as absolute path, . for current directory: "
 read path
 if [ -n "$path" ]
 then 
  cd $path
  echo -e "What do you want the file to be named?"
  read flname
  echo -e "*******************************   $flname  ******************************" > $flname
  echo -e "------------ Compiled by a software from SANTOSH KUMAR DESAI ------------" >> $flname
  echo "The files in this folder to merge are:"
  declare -a var
  var=(*.php *.html *.css *.txt)
  $count=0
  for i in "${var[@]}"
  do
   echo $i
   let count=count+1
  done
  echo "Total : $count files" 
  echo -e "Starting to merge files into one now...."
  for i in "${var[@]}"
  do
   echo -e "copying $i"
   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."
  done
  echo -e "**************************** END OF DOCUMENT ****************************" >> $flname
  echo -e "All files were merged through a shell script from SANTOSH KUMAR DESAI " >> $flname
  echo -e "Total $count files were copied."
  echo -e "Compiling all the files into one file is complete.\n"
  echo -e "The file is named $flname and it will be available in the same directory as other merged files."
  echo -e "Thanks for using this shell script ---- Horopter."
 fi
fi 
echo "Exiting the script."
exit 0


No comments:

Post a Comment