Reputation: 12207
I want the lines starting with one uppercase character to be uppercased, other lines should be not touched.
So this input:
cat myfile
a
b
Cc
should result in this output:
a
b
CC
I tried this command, but this not matches if i use grouping:
cat myfile | sed -r 's/\([A-Z]+.*\)/\U\1/g'
What am i doing wrong?
Upvotes: 1
Views: 246
Reputation: 438238
\U
for uppercase conversion is a GNU sed
extension.
Alternative for platforms where that is not available (e.g., macOS, with its BSD awk
implementation):
awk '/^[A-Z]/ { print toupper($0); next } 1'
Upvotes: 1
Reputation: 58440
This might work for you (GNU sed):
sed 's/^[[:upper:]].*/\U&/' file
Upvotes: 0
Reputation: 10039
sed '/^[A-Z].*[a-z]/ s/.*/\U\1/' YourFile
only on line that are not compliant
Upvotes: 0
Reputation: 781255
When you use the -r
option, you must not put \
before parentheses used for grouping. So it should be:
sed -r 's/^([A-Z].*)/\U\1/' myfile
Also, notice that you need ^
to match the beginning of the line. The g
modifier isn't needed, since you're matching the entire line.
Upvotes: 4