Newbie_Mark
Newbie_Mark

Reputation: 17

search and replace multiple numbers in a file

I am trying to do inline search and replace in a file using Perl 5.10.1

When i search for say a number like 73.10 and replace it with 73.20. It finds 73100.25 and replaces it with 73.200.25 and 73.10 with 73.20.

the file has 6 columns that appear like the below:

text text text 73100.25 25.12 text

text text text 365.8 96.25 text

text text text 23189.73 73.10 text

how do i ensure that it does not replace the wrong number?

`/usr/bin/perl -p -i -e "s/$num1/$num3/g" new_info.txt`;
`/usr/bin/perl -p -i -e "s/$num2/$num4/g" new_info.txt`;

Upvotes: 0

Views: 91

Answers (1)

mpapec
mpapec

Reputation: 50657

perl -i -pe 's/\Q$num1\E/$num3/g' new_info.txt

Upvotes: 1

Related Questions