0

I have data like this in Source_file.txt

5daee1ef55297ba2fac78933

And in Target_file.txt has

$$API_JOB_ID=5daed2a255297ba2fac78930
$$API_JOB_RES=succeeded
$$API_SERVER=awsabc1108

Now, I need to replace the Source_file.txt value in Target_file.txt.

Output should be like below

$$API_JOB_ID=5daee1ef55297ba2fac78933
$$API_JOB_RES=succeeded
$$API_SERVER=awsabc1108

Please note that Source_file.txt values are dynamically changing every time when other processes completed. Hence Target file has to be updated every time with correct $$API_JOB_ID

I would need the Unix command to resolve this.

1
  • What is the interval of updating Target_file.txt? Or what invokes the procedure?
    – arif
    Oct 22, 2019 at 14:04

1 Answer 1

0

Ok, this is kind of dirty, but it should work:

sed 's/\$\$API_JOB_ID=.*$/\$\$API_JOB_ID='"$(cat Source_file.txt)"'/' Target_file.txt

If you want to directly edit your target file instead of printing the modified version to your terminal, use this instead:

sed -i 's/\$\$API_JOB_ID=.*$/\$\$API_JOB_ID='"$(cat Source_file.txt)"'/' Target_file.txt

It's dirty, mainly, because I'm making TOO MANY assumptions about the format of your files, and the command success, heavily depends on those assumptions; if we want to do this right, we need to know exactly what assumptions we can make, but your description was kinda vague. If you think that this can fail cause you can have other formats or more complex structure in your Source_file.txt and Target_file.txt files, we need to know about that.

4
  • Wonderful answer. Its perfectly working. Thanks very much for your time and really appreciate you. Oct 23, 2019 at 14:57
  • I'm glad it was helpful for you; could you please mark my answer as the one that solved your problem? Oct 23, 2019 at 14:59
  • You perfectly made the correct assumptions and exactly what i was looking for. Thanks Million and appreciate your time on this. Sorry to ask you this. How do we make it as its answered?. Oct 23, 2019 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .