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.