ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
You might change the address to /^.{4}$/ but it is the same number of characters and harder to type than ...., and you will need to escape the curly braces I think.
You might change the address to /^.{4}$/ but it is the same number of characters and harder to type than ...., and you will need to escape the curly braces I think.
Your suggestion works nicely ...
Code:
echo "Find four-letter words containing V, using SED with curly braces."
echo "Method of LQ Senior Member astrogeek."
sed -n '/^.\{4\}$/s/v/v/p' $CleanWords >$OutFile
... and lends itself to being a more general solution such as 9-character words containing "w."
Nitpick: the sed solution makes a v-for-v substitution which is not needed for the awk or grep solutions.
Counter-argument to the Nitpick: depending on the overall purpose of the code it might be desirable to make that "v" stand out by coding it this way ...
Code:
echo "Find four-letter words containing V, using SED with curly braces."
echo "Method of LQ Senior Member astrogeek."
sed -n '/^.\{4\}$/s/v/V/p' $CleanWords >$OutFile
Without the substitution the sed does not work ... remember, it is how the tool functions that is the key and not how it compares to another commands process.
You can add -r to the sed switches and the braces should not need to be escaped.
Without the substitution the sed does not work ... remember, it is how the tool functions that is the key and not how it compares to another commands process.
Actually, sed can use the same approach as awk here:
I am impressed by the ingenuity of the various solutions and improvements-on-solutions offered by all the contributors to this thread. Thanks to astrogeek, grail, keefaz, ntubski. Kudos and reps all around. This thread is marked SOLVED!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.