Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Any time the word “The” appears at the beginning of a line, I want to move it to the end of the line and capitalize the new first word in the line. For example, “The heaven” becomes “Heaven the”. I'm trying to test this out for my Library.

share|improve this question
up vote 3 down vote accepted

This should work:

sed 's/^The \(.*\)/\u\1 the/'
share|improve this answer
Hm, that moves 'the' to the end of the line, but it doesn't capitalize the first letter of each word at the beginning of the line. I really appreciate your help. – 에이바 Sep 13 '10 at 16:35
It does. Look at the \u. – cYrus Sep 13 '10 at 16:51

In case your sed doesn't have \u:

awk '$1 ~ "^The" {the=tolower($1); $1=""; char=toupper(substr($0,2,1)); rest=substr($0,3); print char rest, the}' inputfile

Assigning a null to $ leaves the field separator (a space) in place. The first substr() starts at character 2 to skip that space. The comma near the end prints the OFS (output field separator which defaults to a space).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.