Home How to use awk to edit lines in a file
 I have a file that has a bunch of unique entries in it, each one on its own line. I'm trying to take some system variables I've created and insert them into the file on the respective line. I keep getting it inserted on the next line, or a random carriage return. Here is an example of the file: [default] access_key = bucket_location = US cloudfront_host = cloudfront.amazonaws.com  Here is the script / commands I've figured out so far: accesskey="ACCESSKEYWOULDENDUPHERE" awk -i inplace -v x="\$accesskey" '{print} /access_key =/ {print x}' /root/.s3cfg  This is what happens [default] access_key = ACCESSKEYWOULDENDUPHERE bucket_location = US cloudfront_host = cloudfront.amazonaws.com  As you can see, I end up inserting on a new line. My goal is for it to look like this: [default] access_key = ACCESSKEYWOULDENDUPHERE bucket_location = US cloudfront_host = cloudfront.amazonaws.com  I am trying to figure out how to use printf but its just not working out so far.