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.

icon.linkedin.jpgicon.twitter.jpg

  • Subscribe to this RSS Feed
  • Splitting a String in Bash on the FIRST Occurrence of a Character
    06/11/2014 4:52PM
    About a year ago I posted an article about how to split into an array of values based on a given delimiter in bash.

    The following is how to take that same string and split it on the first occurrence of the same user defined delimiter.

    Both use the 'read' command, but in a slightly different way.

    Instead of passing read the -a [aname] parameter which tells it that "The words are assigned to sequential indices of the array variable aname, starting at 0.", we pass is -r which indicates that "Backslash does not act as an escape character.  The backslash is considered to be part of the line.".  This will make sure to include any backslash that is in the string in your output.

    Then, we provide two variables into which we will store the split string.

    #!/bin/bash

    SOURCE_STRING='foo|blah|moo'

    # Save the initial Interal Field Separator
    OIFS="$IFS"

    # Set the IFS to a custom delimiter
    IFS='|'

    read -r KEY VALUE <<< "${SOURCE_STRING}"
    echo "KEY = $KEY, VALUE = $VALUE"

    # Reset original IFS
    IFS="$OIFS"
  • BASH Script With Default Arguments Defined in The Script
    06/02/2014 12:41PM

    Often times you will want to write a BASH script where you don't want to have to keep track of all of the positional command line arguments and/or you might want to configure it with a set of environmental variables while having a default value for each in the script.

    Following is the syntax for declaring them in the shell script, and then an example on how to invoke it.

     #!/bin/bash

    : ${ARG1:="somedefault_arg1"}
    : ${ARG2:="10"}

    echo "ARG1 = $ARG1"
    echo "ARG2 = $ARG2"



    $ ./default-bash-vars.sh
    ARG1 = somedefault_arg1
    ARG2 = 10
    $ ARG1="someOtherArg1" ARG2="20" ./default-bash-vars.sh
    ARG1 = someOtherArg1
    ARG2 = 20

    In the example script, we have two variables, ARG1 and ARG2.  When running the script without providing any additional configuration the default values will be used.  When invoking it and defining the variables on the command line prior to executing the script those values will be used instead.

    This prevents the situation where you potentially have many command-line arguments and then have to jugle the positional $1, $2, .... vars in the script.

  • Unable to Set the Path To java.exe When Running Oracle SQL Developer Under Windows 7
    05/22/2014 1:08PM

    I was trying to run Oracle SQL Developer for the first time on a new machine.  When firing it up, it presented me with a dialog box asking me to "Enter the full pathname for the java.exe file".

    OK, no problem.  So I find the path to the java.exe binary that was just installed with the SDK.  Hit submit . . . and nothing happens.  It blanks out the text field and the dialog box stares back at me.

    I tried pointing it to the java.exe that was in the jre dir.  No joy.

    After a lot of futzing around and doing some searches it turns out that there are a few things that you have to do to get it to run for the first time.

    First, right-click on the Oracle SQL Developer short-cut and select "Run as Administrator".

    Then, in the dialog box, click Browse and navigate to the JDK that comes with the Oracle install.  For me it was in C:\Oracle11G\11.2.0.3\jdk\bin\java.exe

    Once I did that it fired right up.  I then quit, and ran it as my user and it seemed to start up just fine.

  • Pin a "Show Desktop" Link to the Task Bar in Windows 7
    05/19/2014 12:16PM

    To create a short cut and pin it to the task bar in Windows 7 do the following:

    1. Right-click on the Desktop and select New -> Shortcut.
    2. Enter the following in the field labeled "Type the location of the item:"  %windir%\explorer.exe shell:::{3080F90D-D7AD-11D9-BD98-0000947B0257}
    3. Click "Next" and name the shortcut and then click "Finish".
    4. Update the icon so that you will recognize it when you pin it to the task bar.  To do so, right-click on the shortcut and select "Change Icon"
    5. Paste the following in the "Look for icons in this file"  %SystemRoot%\system32\imageres.dll
    6. Select an appropriate icon and click "Apply" and then "OK".
    7. Right-click on the icon and select "Pin to Taskbar".
  • Count The Number of Characters In a Field With awk
    05/12/2014 2:09PM

    A quick one-liner for counting the number of characters in a given field for each line in an ASCII file.

    for i in `cat source.txt`; do echo $i | awk  {'print length($1)}' >> counts.txt

Advanced Search

Categories

Archives