Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.