A Little Ingenuity and a Bit of Code Make the World Go Round

Sometimes I surprise myself with my own cleverness and creativity. Case in point…

At Diamond, we maintain two completely different SKU systems to refer to inventory. There’s a stock code system (prefixed STK or STL), and there’s an item code system (prefixed in a MMMYY system, such as SEP25). Occasionally over the years I’ve been asked why this is, and I have no answer. It was a data design decision made long before I started working for Diamond, and as with many things in the world, it worked and continued on its own inertia. I recall conversations pre-COVID that to standardize on one system, probably the stock code system, would “take three years” to develop.

“Three years” was the timeframe for a lot of things.

Anyway.

I had a Word document that was filled with stock codes. About 150 items total. I had a spreadsheet with both stock codes and item codes. I needed to change the stock codes to item codes in the Word document. And doing it manually — looking up the stock code, replacing the stock code with the item code in the document — would take time.

Y’know,” I thought, “there’s the Linux sed command. That can replace text in a text file from the command line, and you don’t even have to open the file…”

But I didn’t have a text file. I had a Microsoft Word document. Sure, there’s text in the Word document, unless Word did something to compress it or do weird formatting things with it. Would sed work on that?

Well, there was only one way to find out…

I had my Word document, and I cobbled together the necessary command to try the first stock code I had to change…

sed -i 's/STL382233/SEP250250/g' manga.doc

I ran the command in my terminal. I opened the document — if you can read the sed command, yes, it’s a document about manga — and looked to see…

It worked! It worked!

As I said, I had a spreadsheet with both stock codes and item codes, and from there it was a trivial matter of writing a =CONCATENATE function to write all the sed commands I needed, which I would then run as a bash script in terminal.

Screenshot of my bash script in my text editor, showing about a dozen and a half sed commands

The script was run! The codes were changed, from stock to item!

Many hours of tedious work was avoided.

And I was still only on my first cup of coffee for the day.

Even I am staggered sometimes by my own ingenuity.

Published by Allyn Gibson

A writer, editor, journalist, sometimes coder, occasional historian, and all-around scholar, Allyn Gibson is the writer for Diamond Comic Distributors' monthly PREVIEWS catalog, used by comic book shops and throughout the comics industry, and the editor for its monthly order forms. In his over fifteen years in the industry, Allyn has interviewed comics creators and pop culture celebrities, covered conventions, analyzed industry revenue trends, and written copy for comics, toys, and other pop culture merchandise. Allyn is also known for his short fiction (including the Star Trek story "Make-Believe,"the Doctor Who short story "The Spindle of Necessity," and the ReDeus story "The Ginger Kid"). Allyn has been blogging regularly with WordPress since 2004.

Leave a Reply

Your email address will not be published. Required fields are marked *