Post

Linux awk

Linux awk

1
2
3
4
5
6
#输出第2行
ip -6 address show | grep inet6 | awk 'NR  == 2 {print $2}' | cut -d'/' -f1
#输出奇数行
ip -6 address show | grep inet6 | awk 'NR % 2 == 1 {print $2}' | cut -d'/' -f1
#输出大于第三行
ip -6 address show | grep inet6 | awk 'NR > 3 {print $2}' | cut -d'/' -f1

注:print $2 代表第二部分

1
2
3
4
#输出第二部分内容为inet的
ip -6 address show | grep inet6 | awk '$2 == "inet" {print $2}' | cut -d'/' -f1
#输出第二部分内容包含632
ip -6 address show | grep inet6 | awk '/632/ {print $2}' | cut -d'/' -f1
This post is licensed under CC BY 4.0 by the author.