2013-06-26

Sed two-line match and replace using pattern and hold space

Sed is a line-oriented text processing tool, so to match and replace a two-line pattern requires accumulating lines in the hold space then testing if those lines should be changed. Today, I had a chance to use this feature to remap some Hyperion Financial Management (HFM) journal files.

HFM journal files have the following heading format. The scenario and year lines only appear once in a journal file.

!Scenario=s
!Year=yyyy

The task was to remap journal files for only one scenario and year to another scenario. Below is the resulting sed script.

# x = Exchange Pattern and Hold
# H = Hold = Hold + \n + pattern
/!Scenario=/ {
 x
}
/!Year=2010/ {
 H
 x
 s/!Scenario=S1\n!Year=2010/!Scenario=S2\n!Year=2010/
}

Not obvious: In the first rule, there is no output because the pattern space is empty. The second rule always outputs the scenario and year lines regardless of whether they have been changed.

2013-06-07

Excel workbook always prints multiple copies

We had some Excel workbooks that, by default, always printed 7 copies of each sheet. A user had to change the number of copies to 1 each time she printed a sheet and the number of copies always started at 7 after she saved and reopened the workbook. The not obvious solution was to change the printer default for the workbook. Steps below:

  1. Open the workbook in Excel.
  2. Select File, Print, Print Preview.
  3. Select Page Setup.
  4. In the Page Setup dialog, press the Options... button.
  5. In the printer setup dialog, change the field that determines the number of copies. It varies from printer to printer. For example, for HP Laserjet P3005, it is in the Advanced tab, Paper/Output, Copy Count.
  6. Press the OK button to save your change.

2013-05-30

Get Internet Explorer version using WMI StdRegProv

In Windows XP, you could get the version of Internet Explorer on a computer using the "\Applications\MicrosoftIE" namespace in this fragment of VBA: (To use this code in this article in your VBA project, include a reference to Microsoft WMI Scripting 1.2 Library.)
    Dim objSWbemLocator As SWbemLocator
    Dim objSWbemServices As SWbemServices, colSWbemObjectSet As SWbemObjectSet, objSWbemObject As SWbemObject, varValue As Variant

    Set objSWbemServices = objSWbemLocator.ConnectServer(strServer:=".", strNamespace:="\Applications\MicrosoftIE")
    Set colSWbemObjectSet = objSWbemServices.ExecQuery("Select * from MicrosoftIE_Summary")
    For objSWbemObject in colSWbemObjectSet
      Debug.Print objSWbemObject.Version
    Next objSWbemObject
The "\Applications\MicrosoftIE" namespace is not available after the introduction of Vista (and Windows 7), so the alternative is to examine the registry:
Const HKEY_LOCAL_MACHINE = &H80000002
...
    Dim objSWbemLocator As SWbemLocator
    Dim objSWbemServices As SWbemServices, objSWbemObject As SWbemObject, varValue As Variant

    Set objSWbemServices = objSWbemLocator.ConnectServer(strServer:=".", strNamespace:="\root\default")
    Set objSWbemObject = objSWbemServices.Get("StdRegProv")
    objSWbemObject.GetStringValue HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Internet Explorer\", "Version", varValue
    Debug.Print = varValue

2013-02-16

Google Play Music "Couldn't play the track you requested"

I made some MP3 files and uploaded to my Samsung Nexus. Google Play Music (GPMu) would find the files but when I tried to play any of them, it displayed "Couldn't play the track you requested". If I select the files individually using a file browser, I could play them with GPMu, so the file format was recognised. Clearing GPMu's cache and data did not fix the problem.

My workaround was to attach an image to each file using a media library manager then reload the files. Now GPMu can play the files.