我使用 bash 脚本。我有台词
3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:80
我想从这行得到“22,80”。有人能帮我吗?
我使用 bash 脚本。我有台词
3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:80
我想从这行得到“22,80”。有人能帮我吗?
As the delimiter before 20 and 80 is :, you can mainly do it with cut:
$ cut -d: -f2 file
22
80
With bash:
$ while read line
do
  echo ${line#*:}
done < file
22
80
Even with awk:
$ awk -F: '{print $2}' file
22
80
And to complete it, with sed:
$ sed  's/.*://' file
22
80
awk 'BEGIN{FS=":"} {print $2}' file