LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-26-2015, 03:53 PM   #1
tasdca
LQ Newbie
 
Registered: Nov 2008
Location: Memphis, TN - USA
Distribution: RedHat EL55 and Centos
Posts: 6

Rep: Reputation: Disabled
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
 
Old 03-26-2015, 04:20 PM   #2
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Quote:
Originally Posted by tasdca View Post
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.
 
Old 03-26-2015, 04:29 PM   #3
tasdca
LQ Newbie
 
Registered: Nov 2008
Location: Memphis, TN - USA
Distribution: RedHat EL55 and Centos
Posts: 6

Original Poster
Rep: Reputation: Disabled
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
 
Old 03-26-2015, 04:35 PM   #4
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Quote:
Originally Posted by tasdca View Post
Thank you for the quick response.
It worked!
No problem, glad you managed to get it working.

Quote:
Originally Posted by tasdca View Post
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.
 
Old 03-26-2015, 04:57 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 20,843

Rep: Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008
And be very careful doing global changes. Usually pays to check how many records will be affected first before allowing the change.
 
Old 03-26-2015, 05:51 PM   #6
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,173

Rep: Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Number of bits (field in general) required to store decimal number srinietrx Programming 7 11-04-2014 07:13 AM
[SOLVED] How to compare a decimal variable with a number? massy Programming 2 03-03-2014 05:43 AM
How to find the first decimal number in a string ? 5883 Programming 3 08-08-2013 06:48 PM
convert number (not hex) into Decimal number drManhattan Programming 10 10-15-2011 08:53 PM
i need to split a decimal number in such a way that each unit is between 1 and 26 anurupr Programming 8 03-07-2010 10:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration