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.

How does one delete the first known character in a string with sed?

For example, say I want to delete the first character (which is @) in the string "@ABCDEFG1234"

I want sed to verify whether "@" exists as the first character. If so, it should delete the character.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

sed 's/^@\(.*\)/\1/'

^ means beginning of the string

@ your known char

(.*) the rest, captured

then captured block will be substituted to output Sorry, can't test it at the moment, but should be something like that

share|improve this answer
    
great solution many THX yael –  yael Jun 27 '10 at 14:40
2  
The other answer is simpler. –  reinierpost Sep 14 '11 at 7:50
add comment

There's no need to capture and replace.

sed 's/^@//'

This replaces the character @ when it's first ^ in the string, with nothing. Thus, deleting it.

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.