Want to fetch a column with multiple pattern using awk.
How to achieve the same.
Tried
cat test
address : 10.63.20.92/24
address : 10.64.22.93/24
address : 10.53.40.91/24
cat test | awk '{print $3}' |awk -F "/" '{print $1}'
10.63.20.92
10.64.22.93
10.53.40.91
Is there any simple method??
And also, from above output how to read first 3 column to one variable and last column to other variable.
ie,
ip1:
10.63.20
10.64.22
10.53.40
ip2:
90
91
92
anbu23
2
$ awk -F"[ /.]" ' { print $7 } ' file
92
93
91
$ awk -F"[ /.]" ' { print $4"."$5"."$6 } ' file
10.63.20
10.64.22
10.53.40
[user@host ~]$ cat file
address : 10.63.20.92/24
address : 10.64.22.93/24
address : 10.53.40.91/24
[user@host ~]$ cat test.sh
#! /bin/bash
while read add colon IP
do
IP=${IP%/*}
IPfstPrt=${IP%.*}
IPlstPrt=${IP##*.}
echo "$IPfstPrt $IPlstPrt"
done < file
[user@host ~]$ ./test.sh
10.63.20 92
10.64.22 93
10.53.40 91
[user@host ~]$