我只是想/etc/fstab
通过管道column -te
来获得一个格式良好的表格是多么整洁。
但是column
当然无法辨别注释行和挂载点定义,因此注释也被拆分为每个空格并格式化为表格列:
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda2 during installation
UUID=8fa99d69-8dac-4aca-bb61-90f753ba5169 / btrfs defaults,subvol=@rootfs,metadata_ratio=6 0 1
# /home was on /dev/sda2 during installation
UUID=8fa99d69-8dac-4aca-bb61-90f753ba5169 /home btrfs defaults,subvol=@home 0 2
Run Code Online (Sandbox Code Playgroud)
有没有办法column
只制作不以 a 开头的格式行#
?
编辑:看来我需要澄清一下,上面的例子实际上是一个有效的fstab
. Btrfs 具有子卷,可以使用subvol
和subvolid
挂载选项单独挂载。
这也意味着第一列中的设备fstab
不一定是唯一的。
我认为务实的解决方案是让column
在整个文件上做它的事情,然后简单地折叠注释行中的任何多个空格
column -t /etc/fstab | sed '/^#/ s/ \{1,\}/ /g'
Run Code Online (Sandbox Code Playgroud)
否则,除了对行进行编号,分别处理注释和非注释行,然后将它们全部粘在一起之外,我看不到任何其他方法,例如
sort -nk1,1 \
<(nl -nln /etc/fstab | grep -vE '^[[:digit:]]+[[:space:]]+#'| column -t | sed 's/ \{1,\}/\t/') \
<(nl -nln /etc/fstab | grep -E '^[[:digit:]]+[[:space:]]+#') \
| cut -f2-
Run Code Online (Sandbox Code Playgroud)
ste*_*eve -2
按照建议,放弃评论?
grep -v "^#" /etc/fstab | column -te
Run Code Online (Sandbox Code Playgroud)