Search code examples
ubuntusedcommand-linemd5sum

Sed Md5Sum Command


I am attempting to write a script to update a file with the md5 of a jar file.

To get the md5, I can do the command:

 md5sum target/file1.jar | awk '{print $1;'}

This will print the md5 of the file. To use sed to replace the text ${md5}, I can do the command:

sed -i 's/${md5}/md5Output/g' File2.json 

I would like to replace md5Output with the contents of the first command.

Is this possible? Basically the goal is to calculate the md5 of "File1" and place that md5 value in "File2"


Solution

  • @Cyrus thanks for the references! Here is the complete answer for anyone who needs to do the same type of thing

     #!/bin/sh
    
     VARIABLE=$(md5sum target/file1.jar | awk '{print $1;}')
     sed -i "s|\${md5}|$VARIABLE|g" file2.json