2
I am trying to create a sed command that capitalizes the pronoun I in a text file. For example "i like dogs." should be "I like dogs." So far I have:
sed 's/ i / I /g'
This doesn't work in a number of different scenarios. Like if there is punctuation around the i.
Here's a list of scenarios that I have thought of that the command should be able to handle:
- There are multiple 'i's on one line of text. I think this can be addressed just by having the
g
flag at the end. - The 'i' has punctuation around it. For example a comma or period after it, or a quote or parenthesis before or after it.
- The 'i' is the first or last character on the line. Meaning you couldn't just check for whitespace or punctuation around it.
- Any regular 'i's in a word are left alone. For example "firefighter" shouldn't be turned into "fIrefIghter".
A workaround to the
i i
case is to apply the transformation twice. This can be achieved by one command:sed -e 's…' -e 's…'
. – Kamil Maciorowski – 2018-10-05T19:31:16.277I was trying to avoid doing things twice but I suppose if push comes to shove that is the only way. – user10354138 – 2018-10-05T19:34:40.207