0

This question already has an answer here:

I need to add %200 at the end if "address 1.1.1.1". I am using bash on linux if someone can let me know.

Current

ltm node /test/10.90.0.1 {
    address 10.90.0.1
}
ltm node /test/10.90.0.12 {
    address 10.90.0.12
}

ltm node /test/10.90.0.50 {
address 10.90.0.50      
}

Desired, with insertion of %200

ltm node /test/10.90.0.1 {
    address 10.90.0.1%200
}
ltm node /test/10.90.0.12 {
    address 10.90.0.12%200   
}
ltm node /test/10.90.0.50 {
    address 10.90.0.50%200
}

marked as duplicate by don_crissti, Jeff Schaller, techraf, G-Man, Eric Renouf Dec 10 '16 at 2:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    Your desired output does not match the description; none of the "node"s are have an apparent address of 1.1.1.1. – DopeGhoti Dec 9 '16 at 22:15
  • yeah that was an example the current and desired format below to add %200 after the ip address – Vegeta Dec 9 '16 at 22:19
2

I propose this with awk:

awk '/address/ && sub("$","%200") || 1' file.txt

or with sed:

sed '/address/ s/$/%200/' file.txt

If you use the option -i you will directly edit your file.

  • thx that worked – Vegeta Dec 9 '16 at 22:55
2

This achieves what you're requesting.

sed 's/address.*/&%200/' current.txt

Example:

$ sed 's/address.*/&%200/' current.txt
ltm node /test/10.90.0.1 {
    address 10.90.0.1%200
}
ltm node /test/10.90.0.12 {
    address 10.90.0.12%200
}

ltm node /test/10.90.0.50 {
address 10.90.0.50%200
}
$

Not the answer you're looking for? Browse other questions tagged or ask your own question.