mirror of
https://github.com/dathere/100.dathere.com.git
synced 2025-12-19 08:39:24 +00:00
feat: add work in progress lesson 2
This commit is contained in:
parent
e41628ff43
commit
56475ee697
3 changed files with 83 additions and 0 deletions
2
_toc.yml
2
_toc.yml
|
|
@ -13,4 +13,6 @@ chapters:
|
||||||
title: "Lesson 0: Exploring qsv help messages and syntax"
|
title: "Lesson 0: Exploring qsv help messages and syntax"
|
||||||
- file: lessons/1/index
|
- file: lessons/1/index
|
||||||
title: "Lesson 1: Displaying file content with qsv table"
|
title: "Lesson 1: Displaying file content with qsv table"
|
||||||
|
- file: lessons/2/index
|
||||||
|
title: "Lesson 2: Piping commands"
|
||||||
- file: appendix
|
- file: appendix
|
||||||
|
|
|
||||||
10
lessons/2/fruits_extended.csv
Normal file
10
lessons/2/fruits_extended.csv
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
fruit,price,size,availability
|
||||||
|
apple,2.50,medium,available
|
||||||
|
banana,3.00,medium,available
|
||||||
|
strawberry,1.50,small,available
|
||||||
|
orange,2.00,medium,out of stock
|
||||||
|
pineapple,3.50,large,available
|
||||||
|
grape,4.00,small,out of stock
|
||||||
|
mango,1.80,medium,available
|
||||||
|
watermelon,6.00,large,available
|
||||||
|
pear,2.20,medium,out of stock
|
||||||
|
71
lessons/2/index.md
Normal file
71
lessons/2/index.md
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
---
|
||||||
|
jupytext:
|
||||||
|
text_representation:
|
||||||
|
extension: .md
|
||||||
|
format_name: myst
|
||||||
|
kernelspec:
|
||||||
|
display_name: Bash
|
||||||
|
language: bash
|
||||||
|
name: bash
|
||||||
|
---
|
||||||
|
|
||||||
|
# Lesson 2: Piping commands
|
||||||
|
|
||||||
|
:::{admonition} Lesson is a work in progress
|
||||||
|
:class: warning
|
||||||
|
|
||||||
|
This lesson is not complete. Stay tuned!
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
We've been using one command at a time, but what if we want to use multiple?
|
||||||
|
|
||||||
|
For example let's say I want to only see what fruits there are and their availability from `fruits_extended.csv` in a nicely formatted table.
|
||||||
|
|
||||||
|
## Selecting the columns
|
||||||
|
|
||||||
|
Take a brief look at `qsv select`:
|
||||||
|
|
||||||
|
```{code-cell}
|
||||||
|
:tags: ["scroll-output"]
|
||||||
|
qsv select -h
|
||||||
|
```
|
||||||
|
|
||||||
|
There are several ways to select the columns we want. Let's take a look at the headers first:
|
||||||
|
|
||||||
|
```{code-cell}
|
||||||
|
:tags: ["scroll-output"]
|
||||||
|
qsv headers fruits_extended.csv
|
||||||
|
```
|
||||||
|
|
||||||
|
We only want data within the `fruit` and `availability` columns. Let's try selecting the data within those columns:
|
||||||
|
|
||||||
|
```{code-cell}
|
||||||
|
:tags: ["scroll-output"]
|
||||||
|
qsv select 1,4 fruits_extended.csv
|
||||||
|
```
|
||||||
|
|
||||||
|
Great, we got the column data that we're looking for. But how do we run this data through `qsv table`?
|
||||||
|
|
||||||
|
## Command redirection
|
||||||
|
|
||||||
|
If you're not sure what `stdin`, `stdout`, and `stderr` are then we recommend reading the "Command data streams (`stdin`, `stdout`, and `stderr`)" section in the Appendix.
|
||||||
|
|
||||||
|
<!-- Add link to appendix or do a dropdown or continue lesson and explain each one. -->
|
||||||
|
<!-- Improve flow for previous sentence to next one or modify flow. -->
|
||||||
|
|
||||||
|
For example let's say we want to display the previous output with `qsv table`. We can run the following to pipe the output into `qsv table`:
|
||||||
|
|
||||||
|
```{code-cell}
|
||||||
|
:tags: ["scroll-output"]
|
||||||
|
qsv select 1,4 fruits_extended.csv | qsv table
|
||||||
|
```
|
||||||
|
|
||||||
|
Now we've got what we were looking for!
|
||||||
|
|
||||||
|
:::{admonition} Exercise is a work in progress
|
||||||
|
:class: important
|
||||||
|
|
||||||
|
The exercise for this lesson is not available yet. Stay tuned!
|
||||||
|
|
||||||
|
:::
|
||||||
Loading…
Add table
Add a link
Reference in a new issue