Another Word For It Patrick Durusau on Topic Maps and Semantic Diversity

May 13, 2018

When Sed Appears To Lie (It’s Not Lying)

Filed under: Data Mining — Patrick Durusau @ 7:34 pm

I prefer Unix tools, bash scripts and sed in particular, for mining text files.

But most of my sed scripts are ad hoc and ran at the command line. But I needed to convert text extracted from PDF (gs) for import into a spreadsheet.

I had 21 invocations of sed that started with:

sed -i 's/Ad\ ID\ //' $f

All the other scripts up to that point had run flawlessly so I was unprepared for:

sed: -e expression #1, char 73: unterminated `s' command

I love command line tools but error messages are not their strong point.

Disclosure: Yes, yes I did have an error in one of the sed regexes, but it was on line #15, not #1.

Ok, ok, laugh it up. The error message was correct because each line counts as a separate “expression #1.”

I did find the error but only by testing each regex.

Sed scripting tip: In a series of sed invocations, each invocation is “expression #1.”

Hope that saves you from looking for exotic problems with your sed distribution, interaction with your shell escapes, etc. (Yeah, all that and more.)

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress