help with sed

Guys,

Need your help. I am not very experienced Unix programmer.

I need to write a script which would edit a file on multiple servers by remote execution. I am using rexec command for that. The file which i want to edit has multiple lines. I need to edit one particular line which is like HST|ABC|FF|XX|||(where XX value may be different on servers and this is the value which i want to change to the value i would supply to script). anyone has a idea?

Please remember i need to execute this on a remote sever:

rexec gagft01 -l nkl -n '

sed command to edit file

'

(remote environment is HP-UX)

---------- Post updated at 06:30 PM ---------- Previous update was at 05:30 PM ----------

Anyone with a solution?

The script below should do what I think you are asking. You will need to update the variables for:
servers = a space-delimited list of the server names with login IDs
fileName = the full name with path of the file to be edited (assumes the same file on each server
newvalue = the new number to be inserted (assumes the same value for each server)

After executing this script, you will find a new file in each location with the same file name with a suffix of the current date (i.e. _20100325).

#!/bin/bash

#Variables - Update these as necessary
servers=( user1@server1 user2@server2 user3@server3 )
fileName=/path/to/file/file1
newValue=23
today=$(date +%Y%m%d)

#sed Command
sedCommand="sed s/HST|ABC|FF|[0-9][0-9]|||/HST|ABC|FF|${newValue}|||/"

for s in ${servers[@]}; do
    ssh ${s} mv ${fileName} ${fileName}_${today}; ${sedCommand} < ${fileName}_${today} > ${fileName};
done

If you need different values for each server, then this will need some tweaking.

Thanks Dunkar, i will try this

you're welcome... I should clarify... the new file with the date suffix is a backup of the file before the change. The new values are available in the file with the original file name.