linux - 从 fstab 的输出中跳过/数据和/分区

标签 linux bash shell

我有以下输出,我想在输出中也去掉/data &/。

cat /etc/fstab  | egrep -v '^#' | awk '{print $2}'| grep -i "^/" | egrep -v '/etc/fstab|proc|sys|shm|pts|/apps|/boot|home|/opt|/var|/var|/crash|/tmp|"' > /tmp/mounts.txt

输出:

/
/data
/data/logs/mount1
/data/logs/mount2

我只需要显示/data/logs/mount1 &/data/logs/mount2。有什么建议吗?

谢谢, 公斤

最佳答案

awk 可以完成您的管道所做的一切:

awk '
    # skip comments and empty lines
    $1 ~ /^#/ || NF == 0 {next}
    # skip mountpoints not beginning with a slash
    $2 ~/^[^/]/ {next}
    # skip / and /data
    $2 == "/" || $2 == "/data" {next}
    {print $2}
' /etc/fstab

或者,如果您是 linenoise 的粉丝:

awk 'NF&&$1!~/^#/&&$2!~/^[^/]/&&$2!="/"&&$2!="/data" {print $2}' /etc/fstab

关于linux - 从 fstab 的输出中跳过/数据和/分区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50820461/

相关文章:

c - printk 格式中 %pa[p] 中 p 的含义

linux - 构建并配置 apr-util 和 httpd 以在 Linux 上使用 apr-iconv

bash - 在等待多个 bash 进程完成时,我应该使用 ${pods[*]} 还是 ${pods[@]} ?

bash - Grep apache 服务器 500 错误到一个单独的文件

linux - 电子邮件未发送到 hotmail,以及额外的 header

linux cpuset 不工作

arrays - 匹配 shell 中的单词后分割字符串

mysql - 在位于文件夹树中的 MySQL 中运行多个 SQL 文件

linux - 用于解析日志文件然后附加到文件的 Powershell 脚本

c - 重定向标准输出