otter otter
otter otter

Reputation: 129

Overwrite output to file in ubuntu

I want to overwrite the output of the shell command in a single file on the dockenginx container.

perl -pe 's/^server_names_hash_bucket_size 128;/#$&/' default.conf > default.conf

I ran the command, but the contents of the default.conf file are all erased.

perl -pe 's/^server_names_hash_bucket_size 128;/#$&/' default.conf >> default.conf

When I execute this command, the contents are added after that.

What should I do if I want to comment on this phrase "server_names_hash_bucket_size 128" in default.conf?

*External package is not available because it is a dockerginx.

Upvotes: 1

Views: 92

Answers (1)

Thaiminhpv
Thaiminhpv

Reputation: 374

Flag -i of the perl command allows you to edit the file inplace:

-i[extension] edit <> files in place (makes backup if extension supplied)

Now you can use:

perl -i -pe 's/^.*server_names_hash_bucket_size 128;/#$&/' default.conf

Additionally, you can also use sed -i instead of perl -i -pe

sed -i 's/^.*server_names_hash_bucket_size 128;/#&/' default.conf

sed and perl are both available inside nginx docker container.

Upvotes: 4

Related Questions