[PLUG] Sed syntax error

Rich Shepard rshepard at appl-ecosys.com
Tue Nov 15 19:12:58 UTC 2016


On Tue, 15 Nov 2016, Robert Citek wrote:

> 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:

Robert,

   Highly likely: that's what I want to do.

> Or insist on sed using groups:

> 's#\([0-9]\{4\}\)\/\([0-9]\{2\}\)\/\([0-9]\{2\}\)#\1-\2-\3#g'

   Ah, yes. I tried using # as a separator but forgot about using parentheses
for grouping, and I had two extraneous '/' in the command. Unfortunately,
it's still not working for me: "sed: file change-date-format.sed line 6:
invalid reference \3 on ' command's RHS"

   Again, the script:

#!/usr/bin/sed
#
# Change date format from / to -.

s#\([0-9]\{4\}\)\/\([0-9]\{2\}\)\/\([0-9]\{2\}\)#\1-\2-\3#g

   And sample data:

"2014-031","WQ/OS","Water Quality, Indiv. Onsite","WR","14-0 INVESTMENTS, LLC","GRANTS PASS","COSTANZO","SIEGEL","CPCO","Any otherwise unclassified violation","2014/04/10","$4,212.00"
"2014-031","WQ/OS","Water Quality, Indiv. Onsite","WR","14-0 INVESTMENTS, LLC","GRANTS PASS","COSTANZO","SIEGEL","CPCO","Installing or causing to be installed an onsite wastewater treatment system or any part thereof, or repairing or causing to be repaired any part thereof, without first obtaining a permit","2014/04/10","$4,212.00"
"2009-071","WQ/SW","Water Quality, Storm Water","NWR","205 AUTO SALVAGE, INC.","PORTLAND","BELETE","SMITH","CP","Failing to collect monitoring data required in Schedule B of the permit","2009/05/07",$619.00
"2004-159","WQ/SW","Water Quality, Storm Water","NWR","205 AUTO SALVAGE, INC.","PORTLAND","JURRIES","CAMILLERI","CPDO","Any violation related to water quality which is not otherwise classified in these rules.","2005/02/14","$1,335.00"
"2004-159","WQ/SW","Water Quality, Storm Water","NWR","205 AUTO SALVAGE, INC.","PORTLAND","JURRIES","CAMILLERI","CPDO","Failure to submit a report or plan as required by rule, permit, or license, except for a report required by permit compl","2005/02/14","$1,335.00"

Thanks,

Rich







More information about the PLUG mailing list