I just thought how neat it would be to pipe my /etc/fstab
through column -te
to get a nicely formatted table.
But column
of course has no way to discern comment lines and mountpoint definitions, so the comments are also split at every whitespace and formatted into table columns:
# /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
Is there a way to make column
only format lines that don't start with a #
?
Edit: It seems I need to clarify that the example above is in fact a valid fstab
. Btrfs has subvolumes that can be mounted separately with the subvol
and subvolid
mount options.
That also means that the devices in the first column of the fstab
are not necessarily unique.
Best Answer
I think the pragmatic solution will be to let
column
do its thing on the whole file, and then simply collapse any multiple spaces in the comment linesOtherwise, I can't see any way to do it besides numbering the lines, processing the comment and non-comment lines separately, and then sticking it all back together, e.g.