Reputation: 71
My file is
cat bla.txt
AbcDe xYaG
need Abcde Xyzg
I am using sed Didnt work
cat bla.txt | sed "s/.*/\L&/g" | sed "s/\w/\u&/"
LAbcDe xYaG
Thanks it work
perl -pe 's/\w+/\L\u$&/g'
Upvotes: 2
Views: 204
Reputation: 185254
Using perl, the simplest and readable solution ;)
perl -lne 'print ucfirst for split /\b/, lc' file
or :
perl -pe 's/\w+/\L\u$&/g'
Credits to Sundeep for this one
Abcde Xyag
print() # do what you think
ucfirst() # UPPER case the first letter
for() # perform preceding calls for each element of following list
split(/\b/) # split string on word boundaries
lc() # lower-case each element from splited list
Upvotes: 2
Reputation: 23667
$ echo 'AbcDe xYaG' | sed -E 's/\w+/\L\u&/g'
Abcde Xyag
-E
to enable ERE\w+
match one or more word characters, since longest match wins, entire words will be matched\L\u&
here \L
will cause characters to be lowercased, but \u
will override it and cause first character to be uppercaseUpvotes: 1
Reputation: 1581
Using sed
:
sed -r -n 's/^([a-zA-Z])(.*)(\s+)([a-zA-Z])(.*)$/\U\1\L\2\3\U\4\L\5/p' file_name
Output:
Abcde Xyag
Upvotes: 0