I have the below output, i want to get rid of /data & / as well in the output.
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
Output:
/
/data
/data/logs/mount1
/data/logs/mount2
I just need /data/logs/mount1 & /data/logs/mount2 to be displayed. Any suggestions ?
Thanks, KG
awk can do all that your pipeline does:
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
or, if you're a fan of linenoise:
awk 'NF&&$1!~/^#/&&$2!~/^[^/]/&&$2!="/"&&$2!="/data" {print $2}' /etc/fstab
Add " | grep /data/" that will not match / and /data.
For your example that is:
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|"' | grep /data/ > /tmp/mounts.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.