Replace negative numbers with 0 in a file

M

Mayank

X-No-Archive: yes

Hi,

I have to replace all the negative numbers with 0 in a very large
file. How can I do it in Perl/Awk. Negative numbers are of the format
(-0.02:0.01:-1.00) ( 0.11:0.01:-0.01)

I need to change them to

(0:0.01:0) (0.11:0.01:0)

Positive numbers should remain untouched.

Thanks in advance.

Regards
Mayank
 
G

Gunnar Hjalmarsson

Mike said:
Mayank said:
I have to replace all the negative numbers with 0 in a very large
file. How can I do it in Perl/Awk. Negative numbers are of the
format
(-0.02:0.01:-1.00) ( 0.11:0.01:-0.01)

I need to change them to

(0:0.01:0) (0.11:0.01:0)

I think this SED script will do what you want

sed 's/-[^:)]*/0/g'

If there is other info in the file, besides such parentheses with
numbers, I'd rather do (in Perl):

s/-\d+(?:\.\d+)?/0/g;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top