using wildcard with the sed s/// command
I am trying to substitute all the words ending in a "ing" with nothing (aka removing "ing") so essentially I tried this:
sed s/" *ing "// ./myfile but it doesn't work. I have also tried using wildcard with sed several other times but it doesn't seem to do what it is supposed to do. I am thinking that I need to quote the wildcard somehow, but I have tried many different ways. Does the sed substitute command support using wildcard? if it does how do I use it? |
the wildcard in sed is a strange beast
it is actually looking for " " ( spaces ) and only " " no matter how many Code:
sed 's/ .*ing//' ./myfile here . is 'wild' for any character BUT, that will wipe out everything up to the last ing to avoid this you could limit to just alphas ( so space is not part of the pattern ) Code:
sed 's/[a-Z]*ing//' ./myfile Code:
sed 's/[a-Z]*ing//g' ./myfile |
Well I have read the question a few times and the part that catches my eye is:
Quote:
Code:
sed 's/ing//g' file will become "someth" which is not a word |
The real answer is that, no, there are no "wildcards" in sed. Tools like sed and grep use regular expressions, which is a different, more complex, and more powerful beast altogether.
It's well worth the effort to learn at least the basics of regex, as one or another flavor of it is used in most text processing tools and programming languages. Even your bash shell supports it (inside the [[..]] test construct). Here are a few regular expressions tutorials: http://mywiki.wooledge.org/RegularExpression http://www.grymoire.com/Unix/Regular.html http://www.regular-expressions.info/ As for what you call "wildcards", the *nix version is usually called globbing. Globbing is a much less sophisticated descendant of regex used for matching simple patterns in filenames and strings. Your shell uses it in several ways, particularly for matching multiple files at once, and some other tools like find also support them. These pages detail the globbing types used in bash. A google search or two with terms like "globbing tutorial" should turn up more info. globbing extended globbing Here are a few useful sed references for you too: http://www.grymoire.com/Unix/Sed.html http://sed.sourceforge.net/grabbag/ http://sed.sourceforge.net/sedfaq.html http://sed.sourceforge.net/sed1line.txt http://www.catonmat.net/series/sed-one-liners-explained |
Thanks for the help
|
All times are GMT -5. The time now is 09:32 PM. |