0

I am working in MacOS 10.12 and I have 100 files such as this:

My file <structure_is> like this <and_maybe_like> this,
but not quite like this.
But there might be <stuff> like this, too.

I have been trying to convert all of the items in <> to uppercase to see the file look like this:

My file <STRUCTURE_IS> like this <AND_MAYBE_LIKE> this,
but not quite like this.
But there might be <STUFF> like this, too.

I tried using:

find . -name "\*" | xargs sed 's/\<([a-z_][^>]*)\>/\U&/g'

I have also tried using gsed (home-brew):

find . -name "\*" | xargs gsed 's/\<([a-z_][^>]*)\>/\U&/g'

But all I get out is the contents of the files themselves to stdout.

How do I do this?

Kindest regards!

QuietLeni
  • 139
  • 1
  • 3
  • 12

2 Answers2

1

This works on Linux: sed 's/<[^>]*>/\U&/g' file

I don't know if \U is GNU sed only.

Alternately, perl:

perl -pe 's/<.*?>/\U$&/g' file
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
0

< in a regexp is a literal < while \< in GNU sed at least is a word delimiter escape sequence. So, just change your \<to < and \> to > and your gsed script would work fine.

Never escape a character unless you KNOW what you're doing. If you want a literal character c and don't know if you need to escape it or not then you're safer using [c] than \c because at least the former can't turn it into a regexp metacharacter.

Ed Morton
  • 188,023
  • 17
  • 78
  • 185