Skip to content
Advertisement

How to read and update(increment) a value in a file with shell commands

I have a certain file which contains many contents, including a line from the format (for example)

ABC = “x12”

What I need to do is to increment the value, so that after the command it will be

ABC = “x13”

The file itself needs to be updated, no need to create a new file or something similar.

I would appreciate if someone do this for me.

Advertisement

Answer

Here is my quick-and-dirty solution using sed:

JavaScript

Example:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement