Jones Doe
Jones Doe

Reputation: 51

How to edit and move a file from one directory to another in one line in Linux?

Happy new year. I have a question. I want to modify and move a file in /etc/ansible directory to my home directory in one shot.

With sed command i removed the # and empty lines. Now I want to move ansible.cfg to my home directory in the same command.

~$ sudo sed -i.date +%F '/^\s*#/d;/^$/d' /etc/ansible/ansible.cfg

Upvotes: 0

Views: 603

Answers (2)

ctac_
ctac_

Reputation: 2491

You can try like that.

sudo sed -i.$(date +%F) '/^\s*#/d;/^$/d;w filename-in-your-home' /etc/ansible/ansible.cfg

Upvotes: 1

Odd822
Odd822

Reputation: 53

Can you use a file descriptor redirection?

~$ sudo sed -i.date +%F '/^\s*#/d;/^$/d' /etc/ansible/ansible.cfg > /path/to/destination

This won't remove or change the original file, however.

Upvotes: 1

Related Questions