I have a file and want to replace a pattern with another string.
#PBS -N bench1-M1-plt2-size15
#PBS -o /home/results/bench1-M1-plt2-size15.out
./run -d ./results/ --config=bench1-M1-plt2-size15.conf \
--results=bench1-M1-plt2-size15.res config/myConfig.txt -F 2000000
I use this command
sed 's/M1-[^-]*-[^-]/M1-plt32-size10/g' filename
However the output file looks like this:
#PBS -N M1-plt32-size100
#PBS -o /home/mahmood/gem5/results/M1-plt32-size100.out
./run -d ./results/ --config=bench1-M1-plt32-size100.conf \
--results=bench1-M1-plt32-size100.res config/myConfig.txt -F 2000000
Please note an extra ‘0’ character after “size10”. As you can see, in the SED command, size is set to 10, however the output file is “size100”
What is the problem and how can I fix that?
Your regex is not correct. You have
[^-]which will match only 1 non-hyphen character. I believe this is what you intended:OUTPUT: