Home How to use awk to edit lines in a file
Reply: 0

How to use awk to edit lines in a file

user1140
1#
user1140 Published in April 25, 2018, 12:35 pm

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.357999 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO