[PLUG] Sed syntax error

Don Buchholz buchholz at easystreet.net
Tue Nov 15 19:06:33 UTC 2016


You need parentheses around the three sub-expressions on the LHS so when you try to use \1, \2, and \3 on the RHS, sed will know what matching text to use.

Also, don't forget, you don't have ave to use the / character as an expression delimiter ...  If my expressions contain / (e.g. path names), I'll generally switch to | or : to save the headache of escaping all the forward slashes.  E.g.  's: match_expr: replace_expr:' or 's|match this|print that|g'.  

 

On November 15, 2016 10:30:02 AM PST, Rich Shepard <rshepard at appl-ecosys.com> wrote:
>Trying to change the date format from a forward slash (/) to a dash
>(-).
>There's a syntax error in my sed script: "file change-date-format.sed
>line
>6: invalid reference \3 on `s' command's RHS" and I'm not seeing why.
>Here's
>the script:
>
>#!/usr/bin/sed
>#
># Change date format from / to -.
>
>s/[0-9]\{4\}\/[0-9]\{2\}\/[0-9]\{2\}/\1-\2-\3/g
>
>   Please show me what I've done incorrectly here.
>
>Rich
>
>_______________________________________________
>PLUG mailing list
>PLUG at lists.pdxlinux.org
>http://lists.pdxlinux.org/mailman/listinfo/plug

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


More information about the PLUG mailing list