Reputation: 4889
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"
Upvotes: 0
Views: 731
Reputation: 1932
Sed One-liner :
$ sed -i "s/\${md5}/$( md5sum target/file1.jar | awk '{print $1}' )/g" File2.json
Upvotes: 1
Reputation: 4889
@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
Upvotes: 0