Walt Mankowski on 31 Aug 2010 09:36:19 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Sed or awk help?!


On Tue, Aug 31, 2010 at 12:23:44PM -0400, linc wrote:
> Walt Mankowski wrote:
> >On Tue, Aug 31, 2010 at 12:11:50PM -0400, linc wrote:
> >>Walt Mankowski wrote:
> >>>On Tue, Aug 31, 2010 at 12:03:49PM -0400, linc wrote:
> >>>>DOH!  Yeah, you are right.  Have to use something like:
> >>>>
> >>>>sed 's/.CEL//' filename > newfile
> >>>>instead...
> >>>That's still not quite right.  You should escape the period and anchor
> >>>the end of the string.  This is better:
> >>>
> >>>sed 's/\.CEL$//' filename >newfile
> >>Seems to work fine without that??
> >
> >Try it on
> >
> >fooCELbar.CEL
> >
> >I mean, there's a good change that all the instances of CEL occur at
> >the ends of the filenames, but why take a chance?
> >
> >Walt
> 
> HEH!  How about THIS one...:
> 
> sed 's/\.CEL//g' filename > newfile
> Now I know why I hate sed :)

Nope, still wrong.  That will delete all the occurences of ".CEL"
anywhere in the filename.  Again, it will probably work, but it would
fail on something like

foo.CEL.bar.CEL

The best way to match ".CEL" at the end of a string is how I did it in
my example.  First, you need to escape the ".", because otherwise it
matches any character before CEL.  Second, you need to add a $ to the
end of the regex.  That achors it to the end of the string, and
prevents it from matching ".CEL" occuring anywhere else.

I don't know why you decided to add a /g to the end of your
expression.  That causes sed to go a global replace all the occurences
of the regex.  Daniel said he only wanted to replace ".CEL" when it
was at the end of the string.

Walt

Attachment: signature.asc
Description: Digital signature

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug