I have a file (test.txt) that contains string such as:
name1,6.5.8.12,specs1,version1,['66.55.89.12']
name2,19.13.13.159,specs2,version2,['13.13.173.59'; '14.19.232.42']
name3,141.101.196.40,specs3,version3,['11.01.196.0']
1) I want to capture all the strings in the 2nd and 5th columns which are formatted as four numbers separated by dots, and each number can be up to 3 digits.
2) There is one string in the 2nd column, but unlimited strings in the fifth column but they are separated by semicolon.
I tried to use this command to try to capture all fifth column strings (I still need to find out how to capture both 2nd and 5th column), but this command did not work in the first place. It produced empty file:
cat test.txt | cut -d ',' -f5 | grep -P -o '\d{1-3}\.\d{1-3}\.\d{1-3}\.\d{1-3}' > result.txt
How to capture the special format string in the 2nd and fifth column usng grep
. Where the strings are four numbers (from 1 to 3 digits) separated by dots. There is only one string in the 2nd column, but unlimited strings in the 5th but separated by semicolon?
EDIT: The expected output:
6.5.8.12
66.55.89.12
19.13.13.159
13.13.173.59
14.19.232.42
141.101.196.40
11.01.196.0
Please also note that I want the results sorted and unique sort -u
. I do not have repeated strings in the example, but I want to avoid repetition if found in my real file.