Database Reference
In-Depth Information
| sepal_length | sepal_width | petal_length | petal_width | species |
|---------------+-------------+--------------+-------------+------------------|
| 4.6 | 3.2 | 1.4 | 0.2 | Iris-setosa |
| 5.3 | 3.7 | 1.5 | 0.2 | Iris-setosa |
| 5.0 | 3.3 | 1.4 | 0.2 | Iris-setosa |
| 7.0 | 3.2 | 4.7 | 1.4 | Iris-versicolor |
| 6.4 | 3.2 | 4.5 | 1.5 | Iris-versicolor |
| 6.9 | 3.1 | 4.9 | 1.5 | Iris-versicolor |
|---------------+-------------+--------------+-------------+------------------|
Note that we're merely using
sed
to only print the header and the first three body
rows that belonged to the second file in order to illustrate success. While this method
works, it's easier (and less prone to errors) to use
csvstack
(Groskopf, 2014):
$
csvstack Iris-*.csv | sed -n
'1p;49,54p'
| csvlook
|---------------+-------------+--------------+-------------+------------------|
| sepal_length | sepal_width | petal_length | petal_width | species |
|---------------+-------------+--------------+-------------+------------------|
| 4.6 | 3.2 | 1.4 | 0.2 | Iris-setosa |
| 5.3 | 3.7 | 1.5 | 0.2 | Iris-setosa |
| 5.0 | 3.3 | 1.4 | 0.2 | Iris-setosa |
| 7.0 | 3.2 | 4.7 | 1.4 | Iris-versicolor |
| 6.4 | 3.2 | 4.5 | 1.5 | Iris-versicolor |
| 6.9 | 3.1 | 4.9 | 1.5 | Iris-versicolor |
|---------------+-------------+--------------+-------------+------------------|
If the
species
column did not exist, you could have created a new column based on
the filename using
csvstack
:
$
csvstack Iris-*.csv -n species --filenames
Alternatively, you could specify the group names using
-g
:
$
csvstack Iris-*.csv -n class -g a,b,c | csvcut -C species |
>
sed -n
'1p;49,54p'
| csvlook
|--------+--------------+-------------+--------------+--------------|
| class | sepal_length | sepal_width | petal_length | petal_width |
|--------+--------------+-------------+--------------+--------------|
| a | 4.6 | 3.2 | 1.4 | 0.2 |
| a | 5.3 | 3.7 | 1.5 | 0.2 |
| a | 5.0 | 3.3 | 1.4 | 0.2 |
| b | 7.0 | 3.2 | 4.7 | 1.4 |
| b | 6.4 | 3.2 | 4.5 | 1.5 |
| b | 6.9 | 3.1 | 4.9 | 1.5 |
|--------+--------------+-------------+--------------+--------------|
The new column
class
is added at the front. If you'd like to change the order you can
use
csvcut
as discussed earlier in this section.