sed - Only replace a string only once in the entire file -


i have file wish replace string once in entire file ie first match finds should replaced. sed -i 's/foo/foo1/1'

try following:

sed -i '0,/foo/s//foo1/' file 

here,

/foo/ fetch line number of first occurrence of foo, let's #n

then same word searched till line #n , replaced foo1


Comments

Popular posts from this blog

iphone - Three second countdown in cocos2d -

hyperlink - how to do url routing in php -

c - Avoiding Extra Malloc in Linked List (node->next = NULL) -