-1

I need help writing a function for articles in strings. I want to take an input like "MICE OF MEN" and turn it into "MICE of MEN." I've been trying to use awk to break up the pattern into substrings but I've been having trouble printing out something that resembles the original input. Does anyone better understand how to use awk or any other tools to do this?

Thank you for any help.

D. Hen
  • 1
  • 1
  • 1
    please clarify that you want to "lc" the 2nd word of a 3 word phrase, OR the "middle" word of any odd-numbered phrase OR ??? Good luck. – shellter Jul 17 '16 at 21:49
  • 1
    ... or maybe make the word `of` always lower case... – Mark Setchell Jul 17 '16 at 21:50
  • 1
    ...or make every other word lower case or just print "MICE of MEN" given any input string or lc any word that doesn't start with M or... In other words, tell us your requirements, don't just show us one sample input/output and have us try to guess the rules to create that transformation. – Ed Morton Jul 18 '16 at 05:29

1 Answers1

0

You can use the gensub command to replace the pattern " OF " with " of ".

echo "MICE OF MEN" | awk '{ print gensub(/ OF /, " of ", "g")}'
Adam
  • 15,932
  • 27
  • 48