Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# GREP (part2)
## setup
??? quote "First click and follow the instructions below only if you start the course at this stage! Otherwise skip this step!"
{%
include-markdown "pages/bash_manip/bash_manip-0-setup.md"
%}
## Searching patterns (grep)
!!! question "Select all line related of the year 2001 in `nat2021.csv` file"
??? example "Click to show the solution"
```bash
grep ";2021;" nat2021.csv
```
!!! question "How many names have been provided in 2021?"
??? example "Click to show the solution"
```bash
grep ";2021;" nat2021.csv | wc -l
# result: 13501
```
!!! question "Is there more diversity in male or female names in 2021"?
??? example "Click to show the solution"
```bash
# female
grep ";2021;" nat2021.csv | grep "^2" | wc -l
# result: 7112
# male
grep ";2021;" nat2021.csv | grep "^1" | wc -l
# result: 6389
```
!!! question "How many person are called PARIS in 2021"?
??? example "Click to show the solution"
```bash
# female
grep "PARIS;2021;" nat2021.csv
# result 16 (5 male and 11 female)
```
The rare name ([see here for documentation](https://www.insee.fr/fr/statistiques/2540004?sommaire=4767262#documentation)) are set as `_PRENOMS_RARES`.
!!! question "Could you find all rare name ? Do you see any pattern?"
??? example "Click to show the solution"
```bash
grep ";_PRENOMS_RARES;" nat2021.csv
```
People tends to provide more and more rare names.
!!! question "What year was the most prolific fot the name ZINEDINE?"
??? example "Click to show the solution"
```bash
# command
grep ";ZINEDINE;" nat2021.csv | sort -n -t ';' -k4
# result: 1998
```
You can redirect a result and store it in a file thanks to the `>` redirection:
`command > filename`
!!! question "Select all the names from 2005 in a dedicated file?"
??? example "Click to show the solution"
```bash
# command
grep ";2005;" nat2021.csv
```