How to substitute a value in a text file
I have to edit a numerical value e.g. (4.14 for 3.12) that is written in a text file.
The value should be typed and then changed by the value in the text file. The value is part of a line, the location should be found and only the value can be changed. Any ideas? |
Can you provide some more detail? For example, I'm guessing that you want a script that prompts the user for the new value, and then inserts that value in the file.
Will you find the right place in the file based on the actual data, or on the file position (or location on a line)? Are you familiar with basic BASH** scripting?---If not, start here: http://tldp.org/LDP/Bash-Beginners-G...tml/index.html **Are you in fact using Linux? If so, then BASH is the most common scripting language |
Just open the file in vi editor(vi filename) & use the following commands:
Esc key :%s/4.14/3.12/g **g=change globally. |
Or "sed -i 's/4.14/3.12/g' filename"
|
Quote:
I am using Linux and Bash scripting, just starting. I now the location in the file but I can't refer to this with sed i '27s/.../.../g' because the value I want to change won't be the same each time. I would need to read a value, store it and be able to substitute the previous value. |
You should post an example and explain in more detail what you want to achieve. i.e. which values will be substituted and where comes the new value from?
Markus |
Try using variables like
Code:
sed -i "s/kkk/$i/g" file |
I think you need to bookmark+read
http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ If you're talking about interacting with the user to get the new value, read up on while loops and the 'read' cmd in those links. |
All times are GMT -5. The time now is 10:55 AM. |