Reputation: 9
I'm on linux Fedora having a.dat
text file, which is a table of numbers. I have at columns 1 and 2 very big numbers, greater than 2000000
, all the other numbers are smaller than 1000
. I want to use linux utility which can open a file, search it for containing large numbers (condition is >2000000
) and substitute each found number by the value of a counter which is incremented each time the number is substituted.
Is it possible todo in a terminal using maybe grep
and how it can be done?
Upvotes: 0
Views: 64
Reputation: 70999
You can do what you want using awk
. Typically you can replace in a file using sed
, but only replacing values bigger than 2000000 using sed
will be tricky.
If I were you I would write a simple ruby or python script. In general it will take you less time and will be easier to maintain and read.
Upvotes: 1