[PLUG] Sed syntax error [RESOLVED]

Robert Citek robert.citek at gmail.com
Tue Nov 15 20:05:38 UTC 2016


On Tue, Nov 15, 2016 at 11:19 AM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
> On Tue, 15 Nov 2016, Robert Citek wrote:
>
>> $ <<< '1996/03/10' sed -re 's#([0-9]{4})/([0-9]{2})/([0-9]{2})#\1-\2-\3#g'
>> 1996-03-10
>
> Robert,
>
>    Yep. This works. I wondered whether my books are out of date and I did not
> need the escape parentheses and brackets.

That's because of the -r (--regexp-extended) switch that is specific
to Gnu. If using a Mac, use the -E switch (or install homebrew).

>> This is why you want to KISS -- use tr, if possible.
>
>    Reading the man page I don't see how to use tr on a file or limit its use
> to only the date field. Will look for more detailed explanation.

tr works on the entire file, or more accurately the entire input stream:

$ cat file.dat | tr / -

But if you truly want to limit your operations to a specific field,
sed isn't the right tool, either.  For that, you'll need something
that parses CSV data (based on your example).  perl, python, ruby,
etc. come to mind.

Regards,
- Robert



More information about the PLUG mailing list