Suppose 3 hosts called host1 ,host2, host3 I want to replace the string 5801 on file /etc/FAKEFILE using +1 for every host,with sed(but perl,awk also ok) using ssh. Must return 5802 on host1 5803 on host2 5804 on host3 Thanks

  • Are the hostnames somehow included in the file, or do you want to change a string depending on actual machine hostname separately for each machine?
    – techraf
    Sep 30, 2015 at 17:38
  • Depending on machine number,on host1 5802+1 return 5803,on host2 5802+2 return 5804,and so on
    – elbarna
    Sep 30, 2015 at 17:42

1 Answer 1



for i in 1 2 3
    N2=$((N2 + 1))
    CMD="sed -i 's/${N1}/${N2}/' /tmp/file"
    echo "running $CMD on host$i..."
    ssh user@host$i "$CMD"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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