From 830bbc65912a484b5f687e431aae46d2977847ec Mon Sep 17 00:00:00 2001 From: "alexis.dereeper_ird.fr" <alexis.dereeper@ird.fr> Date: Sat, 23 Nov 2024 14:49:35 +0000 Subject: [PATCH] Update bash-extracting_from_files.md --- docs/pages/bash/bash-extracting_from_files.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/pages/bash/bash-extracting_from_files.md b/docs/pages/bash/bash-extracting_from_files.md index 4541a45..2a3f095 100644 --- a/docs/pages/bash/bash-extracting_from_files.md +++ b/docs/pages/bash/bash-extracting_from_files.md @@ -115,10 +115,12 @@ Sort is particularly useful when you use some key options: !!! question "Look at the first lines after sorting numerically. Do you observe any difference?" -```bash -sort nat2021.csv | head -sort -n nat2021.csv | head -``` +??? example "Click to show the solution" + + ```bash + sort nat2021.csv | head + sort -n nat2021.csv | head + ``` !!! question "Which name was the most popular among all records? Which year?" @@ -146,12 +148,12 @@ The `cut` command allows to cut a line at a specific character and extract a sel * `-d` specify the separator * `-f` specify the field to extract -!!! question "How to extract the name of the top 100 names/year the most provided" +!!! question "Combining with `sort` command, how can you extract the name of the top 30 most popular names and the corresponding year" ??? example "Click to show the solution" ```bash # command - sort -n -t ';' -k4 nat2021.csv | tail -n 100 | cut -d";" -f 2 + sort -n -t ';' -k4 nat2021.csv | tail -n 30 | cut -d";" -f 2,3 ``` The `uniq` command can be used to remove the redundancy. But result need to be sorted to make it work properly/ -- GitLab