bash - Count specific numbers from a column from an input file linux -
i trying read file , count specific number @ specific place , show how many times appears, example: 1st field numbers, 2nd field brand name, 3rd field group belong to, 4th , 5th not important.
1:audi:2:1990:5 2:bmw:2:1987:4 3:bugatti:3:1988:19 4.buick:4:2000:12 5:dodge:2:1999:4 6:ferrari:2:2000:4
as output, want search column 3, , group 2's(by brand name) , count how many of them have. output looking should this:
1:audi:2:1990:5 2:bmw:2:1987:4 5:dodge:2:1999:4 6:ferrari:2:2000:4
4 -> showing how many lines there are. have tried taken approach can't figure out:
file="cars.txt"; sort -t ":" -k3 $file #sorting 3rd field grep -c '2' cars.txt # counts 2's in file including number 2.
i hope understand. , thank in advance.
i not sure mean "group brand name", following output describe.
awk -f':' '$3 == 2' input.txt
if want line count, can pipe wc -l
.
awk -f':' '$3 == 2' input.txt | wc -l
Comments
Post a Comment