Removing The Last N Character From a String in Bash Script with sed

Here is a quick one-liner for trimming a specific number of characters from the end of a string under bash:

# Remove the last 5 characters
$ echo "somestringwith12345" | sed "s/.....$//g"
$ somestringwith

# Remove the last 3 characters
$ echo "somestringwith12345" | sed "s/...$//g"
$ somestringwith12
Continue reading “Removing The Last N Character From a String in Bash Script with sed”

Running Multiple Instances of Notepad++ Under Windows 7

If you want to run multiple versions of Notepad++ under Windows 7 create a .bat file with the following:

"C:\Program Files (x86)\Notepad++\notepad++.exe" -multiInst %1

And simply run the bat file via a cmd prompt/ → Continue reading “Running Multiple Instances of Notepad++ Under Windows 7”

Splitting a String in Bash on the FIRST Occurrence of a Character

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 → Continue reading “Splitting a String in Bash on the FIRST Occurrence of a Character”

BASH Script With Default Arguments Defined in The Script

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 
Continue reading “BASH Script With Default Arguments Defined in The Script”

Unable to Set the Path To java.exe When Running Oracle SQL Developer Under Windows 7

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 → Continue reading “Unable to Set the Path To java.exe When Running Oracle SQL Developer Under Windows 7”

Pin a “Show Desktop” Link to the Task Bar in Windows 7

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”
Continue reading “Pin a “Show Desktop” Link to the Task Bar in Windows 7”

Running Dynamically Generated Hive Queries From a Shell Script

If you want to write a HQL hive query and run it mulitple times from a shell script, each time passing it different data for the query, here is a quick example that should get you started.

The first thing to know is that by specifying n number of -hivevar key value pairs when invoking hive on the command line will allow you to pass that data into the hive process.

For example, if you do the following

$ hive 
Continue reading “Running Dynamically Generated Hive Queries From a Shell Script”

Eclipse Android Development Error executing aapt: Cannot run program “/path/to/aapt”: error=2, No such file or directory: error=2, No such file or directory

Even though the ADT bundle provides a 64 bit version, the system requirements indicate that “64-bit distributions must be capable of running 32-bit applications.”  I failed to see that when installing it under Fedora Core 20 and was getting the following error from Eclipse:

Error executing aapt: Cannot run program "/home/rchapin/sdks/adt-bundle-linux-x86_64-20131030/sdk/build-tools/android-4.4/aapt": error=2, No such file or directory: error=2, No such file or directory  android_sdk    line 1   Android ADT Problem

I checked to see if the file was there.  Yep.  I → Continue reading “Eclipse Android Development Error executing aapt: Cannot run program “/path/to/aapt”: error=2, No such file or directory: error=2, No such file or directory”

Setting up Android in Eclipse, Unable to resolve target ‘android-18’

When setting up Eclipse for Android development, after you have installed the Develeper Tools and NDK Plugins and linked to the ADT-bundle and then imported your project (see othere posts related by searching for ‘android’) I got the following error:

[2014-03-24 14:14:53 - android_sdk] Unable to resolve target 'android-18'

I went and checked to make sure that the Platform.MinPlatformToolsRev property in the ~/path/to/adt-bundle-linux-x86_64-20131030/sdk/tools/source.properties matched that of my project.properties file.

They were both 18.  Eh?  Why the error?

So, in Eclipse, → Continue reading “Setting up Android in Eclipse, Unable to resolve target ‘android-18’”