Kh.Taheri
Kh.Taheri

Reputation: 957

Working with files in Expect

I want to read a file contents, do some processing and write them to another file by using Expect scripting tool.

Let's assume that I have File_A contains the following data:

The IP address of this machine is: "0.0.0.0"

I want to read the contents of File_A, modify them and write them to File_B, which should be like the following:

The IP address of this machine is: "192.168.0.69"

Can anyone please help me with this?

Upvotes: 0

Views: 78

Answers (1)

Kasun Rathnayaka
Kasun Rathnayaka

Reputation: 503

you can use sed command to replace file content as below.Then use move command to make backup file as you want.

sed -i.bk  's/0.0.0.0/192.168.0.69/g' File_A.txt
mv File_A.txt.bk File_B.txt

Explanation:

sed = Stream EDitor -i = in-place (i.e. save back to the original file) The command string:

s = the substitute command

0.0.0.0 = a regular expression describing the word to replace (or just the word itself)

192.168.0.69 = the text to replace it with

g = global (i.e. replace all and not just the first occurred

Upvotes: 1

Related Questions