Reputation: 11
I have filenames and made a failure in my sed script so I get:
"this_is_the_videoIphone.mp4"
"this_is_my_videoNikon.mp4"
"this_is_the_pictureIphone.mp4"
"this_VideoIphone.flv" ... and so on
I want a "_" between that.
a rule could be like this: (one or more [a-z]) followed by ([A-Z] followed by one or more [a-z])
I tried much but nothing works...
filename="$(echo $filename | sed -e 's/\(^.*[a-z]\)\([A-Z][a-z].*$\)/\1_\2/g')"
What is wrong?
Upvotes: 1
Views: 83
Reputation: 58391
This might work for you (GNU sed):
sed 's/\B[[:upper:]]\B/_&/g' file
This inserts a _
preceeding any uppercase character within a word.
N.B. This does not conform to your specification in that it would insert a _
between two consecutive uppercase characters. Nor would it insert said character if the last character of the word was uppercase.
Upvotes: 0