mirror of
https://github.com/dathere/100.dathere.com.git
synced 2025-12-19 08:39:24 +00:00
feat: update lesson 2 and add appendix entry
This commit is contained in:
parent
aed3dad2d7
commit
896e0c59b6
3 changed files with 129 additions and 12 deletions
22
appendix.md
22
appendix.md
|
|
@ -45,3 +45,25 @@ A mapping of qsv release files for an arbitrary version X.Y.Z and platforms they
|
||||||
:::{note}
|
:::{note}
|
||||||
The listed OS/architecture are primarily based on [information from "The rustc book"](https://doc.rust-lang.org/nightly/rustc/platform-support.html).
|
The listed OS/architecture are primarily based on [information from "The rustc book"](https://doc.rust-lang.org/nightly/rustc/platform-support.html).
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
(command-data-streams)=
|
||||||
|
## Command data streams (`stdin`, `stdout`, and `stderr`)
|
||||||
|
|
||||||
|
The terms `stdin`, `stdout`, and `stderr` may commonly be found within qsv's source code and in the lessons.
|
||||||
|
|
||||||
|
Here's a very brief explanation of what each means in the context of a command:
|
||||||
|
|
||||||
|
- `stdin` ("Standard input"): Input data
|
||||||
|
- `stdout` ("Standard out"): Output data
|
||||||
|
- `stderr` ("Standard error"): Error output
|
||||||
|
|
||||||
|
Let's consider the following pipeline as an example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
qsv clipboard | qsv stats -E
|
||||||
|
```
|
||||||
|
|
||||||
|
- There are two commands ran here, each separated by a pipe (`|`).
|
||||||
|
- The output (`stdout`) of `qsv clipboard` is used as the input (`stdin`) of `qsv stats -E`.
|
||||||
|
|
||||||
|
For further explanation you may read online articles regarding piping commands. You may view a few more examples [here](https://zerotomastery.io/cheatsheets/linux-commands-cheat-sheet/#piping-and-command-redirection).
|
||||||
|
|
|
||||||
52
lessons/2/exercise.ipynb
Normal file
52
lessons/2/exercise.ipynb
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Exercise 2: Piping commands\n",
|
||||||
|
"\n",
|
||||||
|
"Pipe the first and second columns of `fruits_extended.csv` into `qsv table`."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"qsv select --help"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"After running that pipeline and viewing the output, try adding `qsv transpose` before `qsv table` in the pipeline and see what the output looks like."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"vscode": {
|
||||||
|
"languageId": "plaintext"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Bash",
|
||||||
|
"language": "bash",
|
||||||
|
"name": "bash"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"name": "bash"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
||||||
|
|
@ -11,13 +11,6 @@ kernelspec:
|
||||||
|
|
||||||
# Lesson 2: Piping commands
|
# 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?
|
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.
|
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.
|
||||||
|
|
@ -49,7 +42,7 @@ Great, we got the column data that we're looking for. But how do we run this dat
|
||||||
|
|
||||||
## Command redirection
|
## 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.
|
If you're not sure what `stdin`, `stdout`, and `stderr` are then we recommend reading the [Command data streams](command-data-streams) section in the Appendix.
|
||||||
|
|
||||||
<!-- Add link to appendix or do a dropdown or continue lesson and explain each one. -->
|
<!-- 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. -->
|
<!-- Improve flow for previous sentence to next one or modify flow. -->
|
||||||
|
|
@ -63,9 +56,59 @@ qsv select 1,4 fruits_extended.csv | qsv table
|
||||||
|
|
||||||
Now we've got what we were looking for!
|
Now we've got what we were looking for!
|
||||||
|
|
||||||
:::{admonition} Exercise is a work in progress
|
Notice that the output of the first command `qsv select 1,4 fruits_extended.csv` was used as the input for `qsv table`.
|
||||||
:class: important
|
|
||||||
|
|
||||||
The exercise for this lesson is not available yet. Stay tuned!
|
|
||||||
|
|
||||||
:::
|
## Exercise 2: Piping commands example
|
||||||
|
|
||||||
|
[](https://mybinder.org/v2/gh/dathere/100.dathere.com/main?labpath=lessons%2F2%2Fexercise.ipynb)
|
||||||
|
|
||||||
|
Pipe the first and second columns of `fruits_extended.csv` into `qsv table`.
|
||||||
|
|
||||||
|
After running that pipeline and viewing the output, try adding `qsv transpose` before `qsv table` in the pipeline and see what the output looks like.
|
||||||
|
|
||||||
|
> Here we show the usage text of `qsv select` for your reference. Solve this exercise using [Thebe](exercises-setup:thebe), [Binder](exercises-setup:binder) or [locally](exercises-setup:local).
|
||||||
|
|
||||||
|
```{code-cell}
|
||||||
|
:tags: ["scroll-output"]
|
||||||
|
qsv select --help
|
||||||
|
```
|
||||||
|
|
||||||
|
::::{admonition} Solution
|
||||||
|
:class: dropdown seealso
|
||||||
|
|
||||||
|
For the first part, you may run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
qsv select 1,2 fruits_extended.csv | qsv table
|
||||||
|
```
|
||||||
|
|
||||||
|
The output should be:
|
||||||
|
|
||||||
|
```
|
||||||
|
fruit size
|
||||||
|
apple medium
|
||||||
|
banana medium
|
||||||
|
strawberry small
|
||||||
|
orange medium
|
||||||
|
pineapple large
|
||||||
|
grape small
|
||||||
|
mango medium
|
||||||
|
watermelon large
|
||||||
|
pear medium
|
||||||
|
```
|
||||||
|
|
||||||
|
The second part is adding `qsv transpose` within the pipeline:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
qsv select 1,2 fruits_extended.csv | qsv transpose | qsv table
|
||||||
|
```
|
||||||
|
|
||||||
|
The output should be:
|
||||||
|
|
||||||
|
```
|
||||||
|
fruit apple banana strawberry orange pineapple grape mango watermelon pear
|
||||||
|
size medium medium small medium large small medium large medium
|
||||||
|
```
|
||||||
|
|
||||||
|
::::
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue