I am looking for sed command or script which will append word at end of line. for example. I want to validate particular filesystem with mount |<filesystem name> command. if nodev parameter is not there then it should add in the fstab file with receptive to the filesystem.
[root@test CIS]# mount |grep /data
/dev/mapper/datavg-lv_data on /data type ext4 (rw,relatime,seclabel,data=ordered)
[root@test CIS]#
i am looking for below output after adding nodev in fstab file
[root@test CIS]# mount |grep /data
/dev/mapper/datavg-lv_data on /data type ext4 (rw,relatime,seclabel,data=ordered,nodev)
[root@test CIS]#
That is relatively easy: the dollar sign "$" represents the line end in regular expressions, hence:
sed 's/$/ nodev/' /some/file
will append nodev to every line at the end - it substitutes the line end with the text. Since you want only certain lines to be modified you can add a regular expression in front to only affect certain lines:
sed '/nodev/ ! s/$/ nodev/' /some/file
will append nodev only to lines which don't contain the string already. You probably want to refine this a bit more but the principle should be obvious by now.
PS: checking a filesystems current status with the mount/icode]command and then modify the mount table accordingly is a dangerous proposition: it could already be changed alredy but not been remounted so far. Whenever you change such a thing always base the decision to apply the change on the thing you are modifying, not something else - in this case on the content of the file /etc/fstab .
Also notice that you said you want to change the end of line. You haven't told us your OS but if it is Linux the /etc/fstab has two columns after where you should place your change, here iis the one from my laptop, for example:
Hello,
Because, In mount command output, it shows default option which are set on particular filesystem. which is not showing in /etc/fstab file. it only show defaults word there.
[root@test CIS]# mount |grep /data
/dev/mapper/datavg-lv_data on /data type ext4 (rw,relatime,seclabel,data=ordered)
[root@test CIS]#
I just tried you command. its working fine but i need specific to file system. i have data and data1 mount point. it should apply only /data only.