bash - search and replace with sed not working -
i use sed search , replace, doesn't seem working. guess i'm making stupid mistake can't spot.
here file.txt:
pfpr03 pa1448770 pfpr03 pa1448780 pfpr03 pa1448790 pfpr03 pa1448800 pfpr03 pa1448810 pfpr03 pa1448830 pfpr03 pa1448840 pfpr03 pa1448850 pfpr03 pa1448860 pfpr03 pa1448870
i want change pa1448770 pa14_48770, ie. adding underscore after pa14.
here few examples of i've tried, none of them affecting file @ all:
sed 's/^pa14/pa14_/g' file.txt sed 's/^pa14([0-9]*)/pa14_\1/' file.txt
any appreciated,
it because ^
means line start. use \b
word boundary:
sed 's/\bpa14/pa14_/g' file pfpr03 pa14_48770 pfpr03 pa14_48780 pfpr03 pa14_48790 pfpr03 pa14_48800 pfpr03 pa14_48810 pfpr03 pa14_48830 pfpr03 pa14_48840 pfpr03 pa14_48850 pfpr03 pa14_48860 pfpr03 pa14_48870
ps: on osx (bsd) sed
use:
sed 's/[[:<:]]pa14/pa14_/g' file
Comments
Post a Comment