LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   4gig file trying to replace decimal number A with decimal number B (https://www.linuxquestions.org/questions/linux-software-2/4gig-file-trying-to-replace-decimal-number-a-with-decimal-number-b-4175537938/)

tasdca 03-26-2015 03:53 PM

4gig file trying to replace decimal number A with decimal number B
 
I want to change one number string, to another.
I thought it would be easy. But, I'm not finding it.

I thought sed would be just the thing.
I tried the following. But, it does not change the numnber.
sed -n 's/ 6947465.41/ 6947477.98/' minv_tst.txt

This is the record, in the file (wrapped):
1109 111 111 0 0 0 0 0 0 6947465.41 5792148 592988.7

Any ideas with sed, or other linux tools, please let me know.
I am on Centos 6

Thank you

joe_2000 03-26-2015 04:20 PM

Quote:

Originally Posted by tasdca (Post 5338082)
I want to change one number string, to another.
I thought it would be easy. But, I'm not finding it.

I thought sed would be just the thing.
I tried the following. But, it does not change the numnber.
sed -n 's/ 6947465.41/ 6947477.98/' minv_tst.txt

This is the record, in the file (wrapped):
1109 111 111 0 0 0 0 0 0 6947465.41 5792148 592988.7

Any ideas with sed, or other linux tools, please let me know.
I am on Centos 6

Thank you


Try
Code:

sed -i 's/ 6947465.41/ 6947477.98/g' minv_test.txt
-i stands for in-place. I.e., it will actually modify the file. Ideally try it with a small test file first and have a backup from the "real" file around when you run sed commands on it.

tasdca 03-26-2015 04:29 PM

Thank you for the quick response.
It worked!

I'm not new to linux. But, I've never used sed or awk.
I'll tell you, I tried, I don't know how many variations of that code.
I did use the "-i" once or twice. But, I used it along with other "-" options.
When I did that, it actually Zeroed my file.

Anyway, Thank you again!

Tony

joe_2000 03-26-2015 04:35 PM

Quote:

Originally Posted by tasdca (Post 5338099)
Thank you for the quick response.
It worked!

No problem, glad you managed to get it working.

Quote:

Originally Posted by tasdca (Post 5338099)
When I did that, it actually Zeroed my file.

Yikes. That's why you should play with test files until you get the commands right.

syg00 03-26-2015 04:57 PM

And be very careful doing global changes. Usually pays to check how many records will be affected first before allowing the change.

allend 03-26-2015 05:51 PM

Being pedantic, I would escape the period in the search expression, so that the search includes a literal decimal point rather than a match for any character.
Code:

sed -i 's/ 6947465\.41/ 6947477.98/g' minv_test.txt


All times are GMT -5. The time now is 07:59 AM.