1

I am trying sed s/\w/\u/g but it doesn't do anything. I think because it doesn't recognize the \u ?

GNU sed version 4.1.2

0

1 Answer 1

2
sed 's/\w/\u&/' 

\u must apply to something; by itself it does nothing; in this case & means "whatever matched the search pattern". g is to be omitted if you want just the first letter; if you include g it will make uppercase all letters.

4
  • 1
    it's not working for some reason... actually what i do is this sed "s/.*/\L&/g" | sed "s/\w/\u&/" because i first want to lowercase everything Commented Nov 27, 2016 at 20:33
  • sed -e 's/.*/\L&/' -e 's/\w/\u&/' absolutely works, I have tested it. Can you try ls -l | sed -e 's/.*/\L&/' -e 's/\w/\u&/' as a quick test? Commented Nov 27, 2016 at 20:37
  • it just trims the first letter for some reason... weird Commented Nov 27, 2016 at 20:51
  • 1
    This requires GNU sed. It won't work on standard UNIX / BSD sed. Commented Apr 27, 2017 at 5:41

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.