Welcome to my website. I am always posting links to photo albums, art, technology and other creations. Everything that you will see on my numerous personal sites is powered by the formVistaTM Website Management Engine.


  • Subscribe to this RSS Feed
  • One-Liner for Converting CRLF to LF in Text Files
    03/17/2015 10:31AM

    If you have text files created under DOS/Windows and need to convert the CRLF (carriage return and line feed) characters to LF (line feed) character, here is a quick one-liner.

    $ cat file.txt | perl -ne 's/\x0D\x0A/\x0A/g; print' > file.txt.mod

    You can also use dos2unix, however, especially under Cygwin I have seen dos2unix fail without giving any meaningful information about why it was unable to complete the task.  In that case, you can just do it by hand. 

  • Configuring Eclipse to Replace Tabs with Spaces for Indentation
    01/23/2015 6:46PM

    Following are two basic settings (I believe that there are other language specific, C++ for instance, settings as well).

     For Java:

    Window->Preferences->Java->Code Style->Formatter->
    Click on 'New' to create a new profile and select the profile that you want to copy
    Then click 'Edit' and select 'Spaces Only' from the 'Tab Policy' dropdown.

    You can further set the indentation and tab size.

    For default text editor:

    Window->Preferences->General->Editors->Text Editors->Insert spaces for tabs

  • Parsing Command Line Arguments with getopt in Bash
    12/07/2014 10:01PM

    When writing utility scripts in Bash it is tempting to simply pass positional arguments, use $1, $2, etc. and be done with it.  However if you want to either share this utility with other members of your team and/or incorporate it into your system, it makes sense to implement your command line argument parsing in a more flexible and maintainable manner.

    Using getopt you can very easily pass a variety of command line options and arguments.

    Following is a link to a GitHub Gist with an example that illustrates the implementation of flags, options or arguments with values and long option names.



  • Passing an Array as an Argument to a Bash Function
    10/20/2014 1:57PM

    If you want to pass an array of items to a bash function, the simple answer is that you need to pass the expanded values.  That means that you can pass the data as a quoted value, assuming that the elements are whitespace delimited, or you can pass it as a string and then split it using an updated IFS (Internal Field Separator) inside the function.

    Following is an example of taking the output of a Hive query (a single column that is separated by new lines), wrapping it in quotes and passing it as a single value to the function.


    # This function will accept the expanded elements of the array
    function foo() {

       # Loop through elements in the first argument passed.
       # In this case, each is separated by whitespace so we do
       # not need to change the IFS
       for i in $1
          echo "i = $i"

    # Dynamically build our hive query
    HIVE_QRY="use somedb; select some_column from some_table;"

    # Dynamically build the hive command to execute
    CMD="hive -e '$HIVE_QRY'"

    # Execute the hive query in a subshell and store the result in
    # the 'QRY_RETVAL' variable
    QRY_RETVAL=$(eval $CMD)

    # Call the foo method and pass it the output of the query, /QUOTED/
    # so that it will be passed as a single argument and not a series
    # of arguments for each row returned by the query
    foo "${QRY_RETVAL}"

  • Restarting Individual Services or the Entire HDP Stack in the Hortornworks Virtual Sandbox
    10/13/2014 12:18PM

    I'm using the Hortonworks Virtual Sandbox for development and testing and wanted to restart the HDP stack without (of course) having to restart the VM.

    It took me a little while to figure out how to go about it as Internet searches on the topic revealed very little.

    It turns out that Hortonworks have set up their own service on the box, startup_script.

    If you take a look at /etc/init.d/startup_script you will see that it calls a number of other shell scripts in /usr/lib/hue/tools/start_scripts/

    To restart the whole stack simply issue the following command:

    # service startup_script restart

Advanced Search