Hopefully this is a simple question for someone out there. I'm pretty sure I know what I need to use, but I can't figure out how to make it work. Here's the issue:
I have a flat file database. Lets just call it file.db
Here are some sample lines from file.db
#file.db
#
line1|example|sample|name|flag|blah
line2|example|sample|name|flag|blah
line3|example|sample|name|flag|blah
Basically the script calculates a MD5 hash of a tar file. Lets say the hash of the tar file = 1234abcd
I need to append the MD5 sum and another separator (|) to a specific line in file.db
For example:
#file.db
#
line1|example|sample|name|flag|blah
line2|example|sample|name|flag|blah|1234abcd
line3|example|sample|name|flag|blah
The line that it gets appended to will of course be controlled by a variable. I have tried using sed and awk but just cannot figure out the syntax.
UPDATE
Thank you guys, have the solution now. Here is what I ended up doing:
HASH=`md5sum tmp/$URL.tgz | awk '{ print $1 }'`
DBLINE=5
awk -v OFS="|" -v l="$DBLINE" -v h="$HASH" 'NR==l{print $0,h;next}1' databases/$WEB > /tmp/$WEB.tmp && mv /tmp/$WEB.tmp databases/$WEB
Thank you Kent, and everyone else that answered.