Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace certain strings from text with SED and REGEX

Tags:

regex

sed

I have the following strings in a text file (big one, more like these and different):

79A18D7F-1517-5981-8446-3A0452727B06
7842A72D-1517-5281-84E4-EAEF09B743F7
6040BEE7-1517-5982-84C1-419B224E647E
615F2747-1517-5981-84AF-787C34967FB2
7468A3E3-1517-5931-84B3-3FC3F701C269

I can find them using grep and regex:

'[0-9A-F]{8}-[0-9]{4}-[0-9]{4}-[0-9A-F]{4}-[0-9A-F]{12}'

what's the sed regex syntax to delete them because:

sed "s/[0-9A-F]{8}-[0-9]{4}-[0-9]{4}-[0-9A-F]{4}-[0-9A-F]{12}//g"

doesn't seem to work.

Thanks!

like image 999
bsteo Avatar asked May 09 '26 15:05

bsteo


1 Answers

Use sed -r. You are relying on extended regular expression syntax features without escaping them, but with sed -r you don't have to. If you want to actually delete the lines instead of just clearing them, you can use:

sed -r "/regex/d"
like image 81
Explosion Pills Avatar answered May 11 '26 06:05

Explosion Pills



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!