I would like to use sed for search and replace, but it doesn't seem to be working. I guess I'm making a stupid mistake I can't spot.
here is my file.txt:
PFPR03 PA1448770
PFPR03 PA1448780
PFPR03 PA1448790
PFPR03 PA1448800
PFPR03 PA1448810
PFPR03 PA1448830
PFPR03 PA1448840
PFPR03 PA1448850
PFPR03 PA1448860
PFPR03 PA1448870
I want to change PA1448770 to PA14_48770, ie. adding an underscore after the PA14.
Here are a few examples of what I've tried, none of them are affecting the file at all:
sed 's/^PA14/PA14_/g' file.txt
sed 's/^PA14([0-9]*)/PA14_\1/' file.txt
Any help is appreciated,
You are using this token ^
, which means start of string
. That's either the beginning of a line, or of an entire file, but certainly not the beginning of a word.
So this should work :
sed 's/PA14/PA14_/g' file.txt
edit
I highly recommend regex101 to practice your regex. You can test your expressions in live, and they have lot's of good explanations about tokens.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With