Copying code
Copy commands without prompts, or anything else
The cursor line shows which block you’re in; ]c and [c jump to the next and previous code block.
| Key | Copies |
|---|---|
yc |
The commands of the block at the cursor |
yo |
Its output |
yb |
The block as it looks, with prompts |
yt |
A table, as tab-separated values |
yy |
The cursor line |
Y |
Labels for every code block on the screen: type one to copy it |
V, then y |
The lines you select (or drag with the mouse) |
⧉ copy |
With the mouse: the block’s commands |
For the output of terminal sessions made with quarto-term, “the commands” means what you’d type: no prompts ($, >), no callout markers (➊), and commands that continue on the next line stay together. Here ]c went to the first code block of a chapter, and yc copied its two commands:
tomes https://dsatcl.jeroenjanssens.com/ -c 5
Data Science at the Command Li… │ ┃
Welcome │ 5 Scrubbing Data │
Foreword │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │
Preface │ │
1 Introduction │ Two chapters ago, in the first step of the OSEMN model for data science, │
2 Getting Started │ we looked at obtaining data from a variety of sources. This chapter is │
3 Obtaining Data │ all about the second step: scrubbing data. You see, it’s quite rare that │
4 Creating Command-line Tools │ you can immediately continue with exploring or even modeling the data. │
▸5 Scrubbing Data │ There’s a plethora of reasons why your data first needs some cleaning, │
5.1 Overview │ or scrubbing. │
5.2 Transformations, Transf… │ │
5.3 Plain Text │ For starters, the data might not be in the desired format. For example, │
5.3.1 Filtering Lines │ you may have obtained some JSON data from an API, but you need it to be │
5.3.2 Extracting Values │ in CSV format to create a visualization. Other common formats include │
5.3.3 Replacing and Delet… │ plain text, HTML, and XML. Most command-line tools only work with one or │
5.4 CSV │ two formats, so it’s important that you’re able to convert data from one │
5.4.1 Bodies and Headers … │ format to another. │
5.4.2 Performing SQL Quer… │ │
5.4.3 Extracting and Reor… │ Once the data is in the desired format, there could still be issues like │
5.4.4 Filtering Rows │ missing values, inconsistencies, weird characters, or unnecessary parts. │
5.4.5 Merging Columns │ You can fix these by applying filters, replacing values, and combining │
5.4.6 Combining Multiple … │ multiple files. The command line is especially well-suited for these │
5.5 Working with XML/HTML a… │ kind of transformations, because there are many specialized tools │
5.6 Summary │ available, most of which can handle large amounts of data. In this │
5.7 For Further Exploration │ chapter I’ll discuss classic tools such as grep¹ and awk², and newer │
6 Project Management with Ma… │ tools such as jq³ and pup⁴. │
7 Exploring Data │ │
8 Parallel Pipelines │ Sometimes you can use the same command-line tool to perform several │
9 Modeling Data │ operations or multiple tools to perform the same operation. This chapter │
Welcome! Press ? for the keys, Space e for the outline, Ctrl-p to search ▶ terminal term 8/16 Top
Data Science at the Command Li… │ │
Welcome │ This chapter starts with the following files: ┃
Foreword │ │
Preface │ ⧉ copy ▶ send │
1 Introduction │ $ cd /data/ch05 │
2 Getting Started │ │
3 Obtaining Data │ $ l │
4 Creating Command-line Tools │ total 200K │
5 Scrubbing Data │ -rw-r--r-- 1 dst dst 164K Nov 26 11:54 alice.txt │
▸ 5.1 Overview │ -rw-r--r-- 1 dst dst 4.5K Nov 26 11:54 iris.csv │
5.2 Transformations, Transf… │ -rw-r--r-- 1 dst dst 179 Nov 26 11:54 irismeta.csv │
5.3 Plain Text │ -rw-r--r-- 1 dst dst 160 Nov 26 11:54 names-comma.csv │
5.3.1 Filtering Lines │ -rw-r--r-- 1 dst dst 129 Nov 26 11:54 names.csv │
5.3.2 Extracting Values │ -rw-r--r-- 1 dst dst 7.8K Nov 26 11:54 tips.csv │
5.3.3 Replacing and Delet… │ -rw-r--r-- 1 dst dst 5.1K Nov 26 11:54 users.json │
5.4 CSV │ │
5.4.1 Bodies and Headers … │ │
5.4.2 Performing SQL Quer… │ The instructions to get these files are in Chapter 2. Any other files │
5.4.3 Extracting and Reor… │ are either downloaded or generated using command-line tools. │
5.4.4 Filtering Rows │ │
5.4.5 Merging Columns │ Before I dive into the actual transformations, I’d like to demonstrate │
5.4.6 Combining Multiple … │ their ubiquity when working at the command line. │
5.5 Working with XML/HTML a… │ │
5.6 Summary │ 5.2 Transformations, Transformations Everywhere │
5.7 For Further Exploration │ ─────────────────────────────────────────────── │
6 Project Management with Ma… │ │
7 Exploring Data │ In Chapter 1 I mentioned that, in practice, the steps of the OSEMN model │
8 Parallel Pipelines │ will rarely be followed linearly. In this vein, although scrubbing is │
9 Modeling Data │ the second step of the OSEMN model, I want you to know that it’s not │
Copied commands (2 lines) to the terminal (OSC 52) ▶ terminal term 8/16 4%
Where copies go
On your own computer, tomes uses the system clipboard (pbcopy, wl-copy, xclip, or clip.exe), and inside tmux also tmux’s buffer. Over SSH, it uses OSC 52, which most terminals support, so the copy ends up on your own computer. Set clipboard in the configuration to choose (system, tmux, or osc52).