You're right. It could be anything.  See my reference about including
sample input/output data. - Robert

On Tue, Nov 15, 2016 at 11:08 AM, Don Buchholz <[email protected]> wrote:
> Perhaps his file has strings, with slashes, other than dates? Pathnames
> perhaps.
>
> On November 15, 2016 10:53:54 AM PST, Robert Citek <[email protected]>
> wrote:
>>
>> On Tue, Nov 15, 2016 at 10:50 AM, Robert Citek <[email protected]>
>> wrote:
>>>
>>>  On Tue, Nov 15, 2016 at 10:30 AM, Rich Shepard
>>> <[email protected]> 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.
>>>
>>>
>>>  Example input and sample expected data would be helpful.  But if I
>>>
>>> were to guess (which is usually a really bad idea), your input date
>>>  string looks like this:
>>>
>>>  1996/03/10
>>>
>>>  and you want your output data to look like this:
>>>
>>>  1996-03-10
>>>
>>>  If that's correct (highly unlikely because I am guessing), then this
>>> would work:
>>>
>>>  $ <<< '1996/03/10' tr / -
>>>  1996-03-10
>>>
>>>  But if you insist on sed:
>>>
>>>  $ <<< '1996/03/10' sed -e 's#/#-#g'
>>>  1996-03-10
>>>
>>>  Or insist on sed using groups:
>>>
>>>  $ <<< '1996/03/10' sed -e
>>>  's#\([0-9]\{4\}\)\/\([0-9]\{2\}\)\/\([0-9]\{2\}\)#\1-\2-\3#g'
>>>  1996-03-10
>>>
>>>  or
>>>
>>>  $ <<< '1996/03/10' sed -re
>>>  's#([0-9]\{4\})\/([0-9]\{2\})\/([0-9]\{2\})#\1-\2-\3#g'
>>>  1996/03/10
>>
>>
>> Oops!  Corrected:
>>
>> $ <<< '1996/03/10' sed -re 's#([0-9]{4})/([0-9]{2})/([0-9]{2})#\1-\2-\3#g'
>> 1996-03-10
>>
>> This is why you want to KISS -- use tr, if
>> possible.
>>
>> Regards,
>> - Robert
>> ________________________________
>>
>> PLUG mailing list
>> [email protected]
>> http://lists.pdxlinux.org/mailman/listinfo/plug
>
>
> --
> Sent from my Android device with K-9 Mail. Please excuse my brevity.
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to