Ask Your Question
0

advanced shell scripting : pandoc replica [problem] [closed]

asked 2014-11-24 17:33:06 -0500

SantoshHoropter gravatar image

Hi guys, I have this pretty simple shell script that can merge any file type's text into a .doc file. Source code is at the end of this question. Here are few questions on the topic : 1. I want to add headers, footers, index etc through the shell script. Is it possible to do that? 2. Also where can I find useful manual on zenity? 3. How do I make these shell scripts work on other systems which may or may not have zenity? 4. is it possible to change color font and strength (bold, em, underline etc) of text through shell? 5. Any more utilities I could add?

Any genuine concern, suggestion and discussion is accepted.

#!/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

edit retag flag offensive reopen merge delete

Closed for the following reason not a real question by randomuser
close date 2014-12-03 22:01:44.901206

Comments

There are quite a few documentation tools I could suggest, if you could elaborate on what the source files are like, what the end product is used for, etc.

randomuser gravatar imagerandomuser ( 2014-11-24 19:02:05 -0500 )edit

The source files that are to be copied are any plain text type documents which can also be source codes in use, like php, html, ruby,c,cpp etc. the objective is to copy the source text from all those files into one document. The tool is a documenting tool that should have done all sorts of presentable output like indexing the output, paging, etc. Example, we are documenting a report on building a website. Some sick schools such as mine need the source code too. Copying each file is a tedious work considering 100 of them. My tool should do the work for me.

SantoshHoropter gravatar imageSantoshHoropter ( 2014-11-24 19:53:28 -0500 )edit

Documentation can be tedious work :) I'd suggest that you explain principles, and also provide the source files separately; if someone is learning from your example how to build the site, it makes more sense to provide them with a functional example.

randomuser gravatar imagerandomuser ( 2014-11-24 22:43:34 -0500 )edit

OK, sorry to interrupt, but I have no idea what you're asking. This script, it is supposed to merge files? I ran it and it works fine. Only one bit doesn't work:

...
Total 4 files were copied.
...

Actually, no files were copied :). IDK what's wrong though.

abadrinath gravatar imageabadrinath ( 2014-11-25 03:16:58 -0500 )edit
  1. man zenity
  2. I'm not sure about that because some systems can't run even BASH. So, I'm not sure not having zenity would be a big problem. If you really want it to run on different OSs, I can only suggest uname or something of the sort.
  3. Yup, try the command tput or to see the manual, man tput. Also, you can get codes and use them with echo.echo -e "\e[31mHello World\e[0m" would give red text and so, e[31m is red. See this: http://misc.flogisoft.com/bash/tip_colors_and_formatting .
  4. I'm not sure about utilities, but you could just exit if there are no files present. I'd make it much easier on the program :P.
abadrinath gravatar imageabadrinath ( 2014-11-25 03:22:17 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-11-24 19:00:46 -0500

updated 2014-11-24 22:56:58 -0500

Pandoc does all of the things you're trying to do, by declaring headers, footers, and different sources.

Fedora Documentation is written with docbook, and built using a tool called publican . Including a source code example inline is done with an include, as described in https://rlandmann.fedorapeople.org/pug/chap-Users_Guide-Frequently_Asked_Questions.html#id656443

Really, I wouldn't approach the problem with the sort of script you're working on. Moving all of the content from a complex file structure into one flat file doesn't make it easier to understand, or explain it. Code is not structured in a linear fashion, whether it's websites or command line utilities or puzzle games - reading from beginning to end doesn't quite apply.

Try explaining key concepts, like the html section, or a php case switch, or whatever it is, and then include the code example. You don't have to put all the code into the document, just refer to appropriate sections as you go along.

Yeah, it's probably more work than you expected, but it takes work to add value. Feel free to ask the Fedora Docs list for insight, especially if the thing you're working on will be permissibly licensed.

edit flag offensive delete link more

Comments

yeah that's the deal, I want my own version of pandoc... please read title again

SantoshHoropter gravatar imageSantoshHoropter ( 2014-11-24 19:56:38 -0500 )edit

xml parsing is what I needed. It's cross platform and kind of easy! great idea.

SantoshHoropter gravatar imageSantoshHoropter ( 2014-12-03 10:47:59 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-11-24 17:33:06 -0500

Seen: 117 times

Last updated: Nov 24 '14