please assist, can't figure out how to add text after a specific line in txt file.
Trying to add "text-111" after specific ip address in a ip.txt file using bash with sed command. this is how the ip.txt looks before changes:
#### STRT 192.168.1.1 ####
#### END 192.168.1.1 ####
#### STRT 192.168.1.11 ####
#### END 192.168.1.11 ####
#### STRT 192.168.1.111 ####
#### END 192.168.1.111 ####
bash looks like that:
#!/bin/bash
ipaddr=192.168.1.1
sed -i "/$ipaddr/a text-111" ip.txt
after running this command it's adding "text-111" to ip.txt under all line that contains 192.168.1.1 as shown below
#### STRT 192.168.1.1 ####
text-111
#### END 192.168.1.1 ####
#### STRT 192.168.1.11 ####
text-111
#### END 192.168.1.11 ####
#### STRT 192.168.1.111 ####
text-111
#### END 192.168.1.111 ####
expected change:
#### STRT 192.168.1.1 ####
text-111
#### END 192.168.1.1 ####
#### STRT 192.168.1.11 ####
#### END 192.168.1.11 ####
#### STRT 192.168.1.111 ####
#### END 192.168.1.111 ####
Can't figure out how to avoid adding "text-111" under other similar lines?
Please assist on that matter :) Thanks!