I would like to change /etc/fstab inside a script. I want to add the aclattribute to the root partition.
One fstabline entry looks like this:
UUID=730aee20-52b7-4920-75cd-d0d995ef2445 / ext3 errors=remount-ro 0 1
I want to change it to:
UUID=730aee20-52b7-4920-75cd-d0d995ef2445 / ext3 acl,errors=remount-ro 0 1
I thought:
1. Search line with root partition /
2. insert acl after /
How can I do that with sed?
Who needs some 3rd party tool when we all have
awk?Example Output
Explanation
$2~"^/$"Search the 2nd field$2to see if it matches a forward slash by itself^/${$4="acl,"$4}If we see a match, prepend acl to the beginning of the 4th field$4}1This is anawkshortcut which is equivalent toprint $0, i.e. print the whole line (including any alterations we may have made)OFS="\t"Set the Output Field SeparatorOFSto a tab\t. The default is space/etc/fstabThe file we want to use as input