shell scripts

1.sed

1
sed -n '10p' textfile # get the 10th line of the textfile

2.grep

1
2
3
4
5
6
7
8
# if 10th line is 192,102,200,201
sed -n '10p' textfile | grep -o ',' | wc -l # answer is 3, count the occurrences of ','
sed -n '10p' textfile | grep -o '[0-9]*' | wc -l # answer is 4, count the nums
sed -n '10p' textfile | grep -o "[0-9]*"" | wc -l # answer is 4, count the nums

-o, --only-matching
Print only the matched (non-empty) parts of a matching line, with each such part on a separate
output line