Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am creating a command to replace all instances of ; f. to , (frequent). . So i wrote sed -i 's:;[:space:]f.:,[:space:](frequent).:g' with out any change then i wrote sed -i 's:; f.:, (frequent).:g' to only find that it replaces all instances of f that has been written after a ; so its turning ; find to , (frequent).ind

Will any one please let me know about my fault and how to rectify it ?

share|improve this question
    
Did you try sed -i 's/; f./, (frequent)./g'? I just tried it on a file and it worked. –  Alaa Ali Jun 5 '13 at 12:10
    
Its actually same as the second command. As sed supports various delimiters. –  22lk94k943 only Jun 5 '13 at 12:25

1 Answer 1

up vote 1 down vote accepted

The problem in the first case is quoting: If you want to use : as the separator, you cannot use it unquoted in character spaces. Also, . has a special meaning in a regular expression - it matches any character. To match the literal dot, use \.. Moreover, [:space:] must be used inside a character class, so you should use [[:space:]]. Finally, character classes have no meaning in the replacement part of the expression.

This should work:

sed 's/;[[:space:]]f\./, (frequent)./g'
share|improve this answer
    
Thank you very much. –  22lk94k943 only Jun 5 '13 at 12:26

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.