标签:linux pre 表达 ubunt -- nbsp lin 正则 bsp
1、打印每行的最后一列
awk -F "[ ]+" ‘{print $NF}‘
2、打印第一行最后一列
awk -F "[ ]+" ‘NR=1{print $NF}‘
3、打印每行的倒数第二列
echo "1::::2 3 4" | awk -F ‘[: ]+‘ ‘{print $4}‘ 4 echo "1::::2 3 4" | awk -F ‘[: ]+‘ ‘{print $1}‘ 1 echo "1::::2 3 4" | awk -F ‘[: ]+‘ ‘{print $2}‘ 2 echo "1::::2 3 4" | awk -F ‘[: ]+‘ ‘{print $3}‘ 3 无空格 ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[:]+‘ ‘{print $2}‘ 2 3 4 ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[:]+‘ ‘{print $1}‘ 1 无冒号 ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[ ]+‘ ‘{print $2}‘ 3 ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[ ]+‘ ‘{print $1}‘ 1::::2 无加号(正则) ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[ ]‘ ‘{print $1}‘ 1::::2 ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[ ]‘ ‘{print $2}‘ 3 ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[ ]‘ ‘{print $3}‘ 4 无加号,以:空格分割 ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[: ]‘ ‘{print $1}‘ 1 ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[: ]‘ ‘{print $2}‘ ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[: ]‘ ‘{print $3}‘ ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[: ]‘ ‘{print $4}‘ ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[: ]‘ ‘{print $5}‘ 2 ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[: ]‘ ‘{print $6}‘ 3 ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[: ]‘ ‘{print $7}‘ 4 ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[: ]‘ ‘{print $8}‘ ubuntu@ubuntu:~$ echo "1::::2 3 4" | awk -F ‘[: ]‘ ‘{print $9}‘ ubuntu@ubuntu:~$
标签:linux pre 表达 ubunt -- nbsp lin 正则 bsp
原文地址:https://www.cnblogs.com/lxsjl/p/9306492.html