sed regex not working -


i using following command eliminate bold text.

sed 's/\-?[0-9]{1,4}\.[0-9]{1,4}//g' countries.txt 

countries.txt contains data in following format:

canillo 42.5833 1.6667 6

encamp 42.5333 1.6333 6

ordino -42.6 -1.55 6

when run find/replace in sublime above regex, geographical coordinates eliminated. when use sed execute same regex, doesn't work.

please refer the -r extended regular expression argument section @ sed - introduction , tutorial bruce barnett:

because meaning of characters different between regular , extended expressions, need command line argument enable sed use extension.
...
mac os x , freebsd uses -e instead of -r.

so, on macos or freebsd may use

sed -e 's/\-?[0-9]{1,4}\.[0-9]{1,4}//g' countries.txt 

and in other environments:

sed -r 's/\-?[0-9]{1,4}\.[0-9]{1,4}//g' countries.txt 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -