I have a configuration file where I need to append the version in ascending order. For this I have written a shell script. The value is getting appended, but the position is not correct.
<code>Config file
[version]
1.0.0.0, 1.0.1.0, 1.0.2.0, 1.0.3.0, 1.0.3.1, 1.0.4.0, 1.0.4.1, 1.0.5.0, 1.0.5.1, 1.0.6.0, 1.0.6.1, 1.0.6.2, 1.0.7.0, 1.0.7.1, 1.2.2.8, 1.2.2.9, 1.2.2.10, 1.2.2.1, 1.2.3.0, 1.3.0.0, 1.2.3.1,
</code>
<code>Config file
[version]
1.0.0.0, 1.0.1.0, 1.0.2.0, 1.0.3.0, 1.0.3.1, 1.0.4.0, 1.0.4.1, 1.0.5.0, 1.0.5.1, 1.0.6.0, 1.0.6.1, 1.0.6.2, 1.0.7.0, 1.0.7.1, 1.2.2.8, 1.2.2.9, 1.2.2.10, 1.2.2.1, 1.2.3.0, 1.3.0.0, 1.2.3.1,
</code>
Config file
[version]
1.0.0.0, 1.0.1.0, 1.0.2.0, 1.0.3.0, 1.0.3.1, 1.0.4.0, 1.0.4.1, 1.0.5.0, 1.0.5.1, 1.0.6.0, 1.0.6.1, 1.0.6.2, 1.0.7.0, 1.0.7.1, 1.2.2.8, 1.2.2.9, 1.2.2.10, 1.2.2.1, 1.2.3.0, 1.3.0.0, 1.2.3.1,
Suppose if I pass 1.0.7.2, then it should be appended after 1.0.7.1, basically in ascending order.
here is the shell script I wrote to achieve this
<code>#!/bin/bash
# Define the value to append
value_to_append="$1"
# Path to the configuration file
config_file="app.config"
line_number=$(grep -n "[version]" "$config_file" | cut -d':' -f1)
# Append the value after the line_number
sed -i "${line_number}a $value_to_append," "$config_file"
</code>
<code>#!/bin/bash
# Define the value to append
value_to_append="$1"
# Path to the configuration file
config_file="app.config"
line_number=$(grep -n "[version]" "$config_file" | cut -d':' -f1)
# Append the value after the line_number
sed -i "${line_number}a $value_to_append," "$config_file"
</code>
#!/bin/bash
# Define the value to append
value_to_append="$1"
# Path to the configuration file
config_file="app.config"
line_number=$(grep -n "[version]" "$config_file" | cut -d':' -f1)
# Append the value after the line_number
sed -i "${line_number}a $value_to_append," "$config_file"
With this script the value is appending at the start and not in the ascending order. What should I change in script to position the value in proper order.