I want to find a regex which contains the word Sat followed by one or more commas. I used this:
sed -e 's/Sat,+/Sat/ig' myfile.txt > output.txt
But it has no effect despite the fact that the file contains Sat,. Can you correct me?
I want to find a regex which contains the word Sat followed by one or more commas. I used this:
sed -e 's/Sat,+/Sat/ig' myfile.txt > output.txt
But it has no effect despite the fact that the file contains Sat,. Can you correct me?
The + is an extended regular expression symbol, while sed by default uses basic regular expressions.
In a basic regular expression, you may instead use \{1,\} or \+ (only GNU sed seems to know about \+ and it's not standard).
You may also switch sed to use extended expressions by using the -E option.
Related:
sed -E 's/Sat,+/Sat/ig' -E 's/Sun,+/Sun/ig' -E 's/Mon,+/Mon/ig'It gives an errors:sed: can't read s/Sun,+/Sun/ig: No such file or directory. Can you plz point why? – qbq Jul 18 '19 at 19:50-Edoesn't work as an alternative to-e, you just need to add it to switch to extended regexps. Sosed -E -e 's///' -e 's///'should do what you want. – ilkkachu Jul 18 '19 at 19:52sed -E 's/(Mon|Tue|Wed|...|Sun),+/\1/ig'– Kusalananda Jul 18 '19 at 19:54