Conservative. Idaho. Software engineer. Historian. Trying to prevent Idiocracy from becoming a documentary.
Email complaints/requests about copyright infringement to clayton @ claytoncramer.com. Reminder: the last copyright troll that bothered me went bankrupt.
"And we know that all things work together for good to them that love God, to them who are the called according to his purpose." -- Rom. 8:28
Pages
▼
Friday, June 29, 2018
I Thought That I Knew Regular Expressions
sed -e"s/\.\.//g" should remove .. from all stdin lines, right? I am using Cygwin sed.
I do know regular expressions. Font size in Terminal Window too small. Those were commas it was failing to remove.
The -e on the sed is wrong. You use that for specifying a file containing your regexps. You want something like:
sed 's,\.\.,,g'
E.g.
$ cat foo There is one dot . then there are two dots .. and then there are three ... before we end. $ cat foo | sed 's,\.\.,,g' There is one dot . then there are two dots and then there are three . before we end.
Assuming the original puts a space between -e and the starting double quote, you're right, both per my memory and testing just now with Ubuntu 14.04, Gnu sed 4.2.2.
But on Windows, maybe it's doing something wonky with the backslashes? What does echo "\.\." return?
It's been years since I used awk/grep/sed for work... even then it was under Solaris... I agree with you that the searched for pattern will be replaced with NULL, but are you sure the pattern you are looking for is ".." or "/.." ?
It depends on how the shell is handling quoted back-slashes. You might need two of them before each dot instead of one. I never can remember - I just try until it works.
The -e on the sed is wrong. You use that for specifying a file containing your regexps. You want something like:
ReplyDeletesed 's,\.\.,,g'
E.g.
$ cat foo
There is one dot . then there are two dots .. and then there are three ... before we end.
$ cat foo | sed 's,\.\.,,g'
There is one dot . then there are two dots and then there are three . before we end.
Assuming the original puts a space between -e and the starting double quote, you're right, both per my memory and testing just now with Ubuntu 14.04, Gnu sed 4.2.2.
ReplyDeleteBut on Windows, maybe it's doing something wonky with the backslashes? What does echo "\.\." return?
It's been years since I used awk/grep/sed for work... even then it was under Solaris... I agree with you that the searched for pattern will be replaced with NULL, but are you sure the pattern you are looking for is ".." or "/.." ?
ReplyDelete$ more test.txt
ReplyDelete.. This
...that
no
the other...
$ cat test.txt | sed -e"s/\.\.//g"
This
.that
no
$ sed --version
sed (GNU sed) 4.4
Packaged by Cygwin (4.4-1)
See if this helps. I did a search for Kernighan's rule for backslashes. Depends on the number of layers of interpretation.
ReplyDeletehttp://cc2.savs.hcc.edu.tw/~chuavv/awk/Gory-Details.html
It depends on how the shell is handling quoted back-slashes. You might need two of them before each dot instead of one. I never can remember - I just try until it works.
ReplyDeletePhaseMargin -f specifies the file. Without -e "unknown option to 's'"
ReplyDeleteBilly: Copied and pasted and it worked as you found. And with my own test file. I am thinking there is something between those periods.
ReplyDeleteMy eyes are not what they once were. Those were commas, not periods.
ReplyDelete