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
  • Print Lines in a File From a Specific Line Number Until the End of the File with sed
    09/17/2014 11:33AM

    If you know that you want all of the lines in a given file from n to EOF the following is the sed command:

    sed -n '3,$p' some_file.txt

    To print out lines 2 - 5 simply modify it to:

    sed -n '2,5p' some_file.txt

  • Removing the Last Token From a String in Bash with awk
    09/04/2014 5:07PM

    Let's say that you have some number of files for which you want to create a containing directory that is named with all but the last token of the file name, and you want to remove just the last token to create the name of the directory.

    Much easier to explain with an example.  Given this list of files:

    $ ls -1

    You want to create a directory for each of the files as follows:

    foo_5_sometrash should have a directory named foo_5.

    Further, let's assume that you have thousands, or hundreds of thousands of files.  In that case doing it via a script while you get a cup of coffee is the preferred solution.

    The work will be done within a for i in loop iterating over the output from ls with a nested awk command.

    for i in `ls -1`; do DIRNAME=$(echo $i | awk -F_ '{$NF=""; print $0}' | sed 's/ /_/g' | sed 's/_$//g'); mkdir $DIRNAME; done

    Here is the command broken down:


    will set the var $DIRNAME to the result of the scripting within the parenthesis.

    awk -F_ '{$NF=""; print $0}

    will set the field separator to a '_', the character on which you will be 'splitting' your string.  '$NF=""' will set the last field to an empty string and then the 'print $0' will print the entire input line.

    The following sed commands will replace the spaces generated by the awk command with the original separators, '_', and then remove the spurious, trailing '_'.

  • Backspace, Delete, and/or Return Key Stops Working in Oracle SQL Developer
    08/29/2014 9:09AM

    So, I figure up SQL Developer to run some queries against a QC server and for some reason, I am no longer able to use the backspace, delete, or return keys to edit .sql files opened in the program.

    I tried opening a new .sql file, and restarting SQL Developer.  I then tried restarting Windows.  None of those worked.

    After a bit of searching I found a forum posting that indicated by going to Tools/Preferences/Accelerators and clicking the "Load Preset..." button in the bottom right of the dialog box would fix the problem.  My guess is that some key mapping preference file had gotten corrupted some how and that by replacing it with a default that it fixes the problem.

    After doing so, I was back in business.

  • Checking that Input or a Variable is an Integer in BASH
    08/26/2014 9:02AM

    Here is a quick snippet for checking whether or not a variable is a valid integer in BASH.  It is also a howto for regular expressions in a shell script.

    # Make sure that FOO is an integer
    if [[ ! "$FOO" =~ ^[0-9]+$ ]]; then
            echo "The FOO was NOT an integer"

  • How To Benchmark Disk I/O
    08/14/2014 12:24PM

    Here is a quick snipped on how to benchmark Disk I/O with dd.

    $ time sh -c "dd if=/dev/zero of=/home/rchapin/test.zeros bs=1024k count=10000 && sync"

    10000+0 records in
    10000+0 records out
    10485760000 bytes (10 GB) copied, 81.4124 s, 129 MB/s

    real    1m21.950s
    user    0m0.810s
    sys     0m5.474s

    Will do a write test of 10GB.

    You can do a similar test and read from that file generated and write to another file or /dev/null to get an idea of the read speeds.

    See the this link for more information.

Advanced Search