regex question

4 views
Skip to first unread message

Robert Mckennon

unread,
Oct 1, 2023, 9:30:29 PM10/1/23
to jax...@googlegroups.com
Hey.. I'm looking for some regex help.

I have a large csv file like:
name,v1,v2,v3
s1,1.0,2.0,3.0
s2,1.1,2.1,3.1
s3,Error: blah3,2.0,3.1
s4,1.0,2.0,Error: blah4
s5,1.0,Error: blah5,3.0

I'm looking to remove all the "Error"(s).

So I start with: 
rob@Galadriel:~/test$ sed -e 's/Error.*,//g' test.csv
name,v1,v2,v3
s1,1.0,2.0,3.0
s2,1.1,2.1,3.1
s3,3.1
s4,1.0,2.0,Error: blah2
s5,1.0,3.0

And this sort of works (ok, not really).  I think I need to tell it "up TO the next comma" because it's removing the comma.

Then there is the case on line s4 where it's the EOL.  So I need some sort of OR statement there.  (comma OR EOL).

Can some regex guru throw me a bone here please? 


Rob.


timhol...@gmail.com

unread,
Oct 1, 2023, 9:35:08 PM10/1/23
to jax...@googlegroups.com
Maybe something like "/Error:,*[^\,$]/" might do. Should match on the "Error and anything up to, but not including comma or end-of-line if I've got it right.

   Tim
--
You received this message because you are subscribed to the Google Groups "JaxLUG" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jaxlug+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jaxlug/CAErk9YCnYAL8QF2b%3DG67tUK-Ogxcyt8A%3DehWxz%3Do1bzt1SX6WA%40mail.gmail.com.

Robert Mckennon

unread,
Oct 1, 2023, 10:00:10 PM10/1/23
to jax...@googlegroups.com
Hi Tim!

Thank you for the quick reply!

That's closer... it covers the 'up to the comma', and the EOL problem,   but it leaves the rest of the error messages:

rob@skylan:~/test$ sed -e 's/Error:,*[^\,$]//g' test.csv
name,v1,v2,v3
s1,1.0,2.0,3.0
s2,1.1,2.1,3.1
s3,blah3,2.0,3.1
s4,1.0,2.0,blah4
s5,1.0,blah5,3.0

I have an assortment of Error messages....
Error:  blah1
Error:  blah2
Error:  foo

etc... and they can be lengthy, but NOT contain any commas.


Rob.




timhol...@gmail.com

unread,
Oct 1, 2023, 10:06:43 PM10/1/23
to jax...@googlegroups.com
I did a sloppy copy. Not "Error,.*[", but "Error:.*[". The comma following the ":" should not be there.

Rajesh Verma

unread,
Oct 1, 2023, 10:17:49 PM10/1/23
to jax...@googlegroups.com
Do you accept Python? Worked for the example errors.

Rajesh Verma


striperror.py

Robert Mckennon

unread,
Oct 1, 2023, 10:29:34 PM10/1/23
to jax...@googlegroups.com
I did think the comma was out of place, so I tried it with a period,and it's removing to the EOL:

rob@skylan:~/test$ sed -e 's/Error:.*[^\,$]//g' test.csv
name,v1,v2,v3
s1,1.0,2.0,3.0
s2,1.1,2.1,3.1
s3,
s4,1.0,2.0,
s5,1.0,


I'll try more tomorrow... thank you!

Rob.


On Sun, Oct 1, 2023 at 10:06 PM <timhol...@gmail.com> wrote:

Robert Mckennon

unread,
Oct 1, 2023, 10:30:06 PM10/1/23
to jax...@googlegroups.com
Yes, I do accept python... I'll try this out tomorrow!

Thanx!

Rob.


Rajesh Verma

unread,
Oct 1, 2023, 10:37:40 PM10/1/23
to jax...@googlegroups.com
Great, let me know if you need any help with changes.

Rajesh Verma


Reply all
Reply to author
Forward
0 new messages