Delimited text (CSV/TSV)

CSV is the default format. Use --delimiter (-d) for other separators and --no-header (-H) for files without a header row. For finer control, use --input-delimiter and --output-delimiter (-D) to set them independently, --no-input-header and --no-output-header to control headers per side, or -F/-O to force a specific format regardless of extension.

Reading CSV

rush run 'df |> dplyr::filter(body_mass_g > 5500) |> dplyr::select(species, bill_length_mm, body_mass_g)' penguins.csv
#> species,bill_length_mm,body_mass_g
#> Gentoo,50,5700
#> Gentoo,50,5700
#> Gentoo,49,5550
#> Gentoo,48.4,5850
#> Gentoo,49.3,5850
#> Gentoo,49.2,6300
#> Gentoo,50.2,5700
#> Gentoo,47.8,5650
#> Gentoo,50,5550
#> Gentoo,59.6,6050
#> Gentoo,49.6,5700
#> Gentoo,50.5,5550
#> Gentoo,50.4,5550
#> Gentoo,54.3,5650
#> Gentoo,49.8,5700
#> Gentoo,49.5,5800
#> Gentoo,50.7,5550
#> Gentoo,48.6,5800
#> Gentoo,51.1,6000
#> Gentoo,45.2,5950
#> Gentoo,50.8,5600
#> Gentoo,52.1,5550
#> Gentoo,49.5,5650
#> Gentoo,55.9,5600
#> Gentoo,49.8,5950
#> Gentoo,55.1,5850
#> Gentoo,48.8,6000
#> Gentoo,50.4,5750

Reading TSV

rush run -d "\t" 'head(df, 3)' cities.tsv
#> city\pop\province
#> Amsterdam\921402\Noord-Holland
#> Rotterdam\655468\Zuid-Holland
#> Utrecht\361924\Utrecht

Delimiter control

--delimiter (-d)

Override the delimiter for both reading and writing:

rush run -d "\t" 'head(df, 3)' penguins.csv | cat
#> species_island_bill_length_mm_bill_depth_mm_flipper_length_mm_body_mass_g_sex_year
#> Adelie,Torgersen,39.1,18.7,181,3750,male,2007
#> Adelie,Torgersen,39.5,17.4,186,3800,female,2007
#> Adelie,Torgersen,40.3,18,195,3250,female,2007

--input-delimiter

Override only the input delimiter while keeping the output as CSV:

rush run --input-delimiter "\t" 'head(df, 3)' cities.tsv
#> city,pop,province
#> Amsterdam,921402,Noord-Holland
#> Rotterdam,655468,Zuid-Holland
#> Utrecht,361924,Utrecht

--output-delimiter (-D)

Override only the output delimiter:

rush run -D "|" 'head(df, 3)' penguins.csv
#> species|island|bill_length_mm|bill_depth_mm|flipper_length_mm|body_mass_g|sex|year
#> Adelie|Torgersen|39.1|18.7|181|3750|male|2007
#> Adelie|Torgersen|39.5|17.4|186|3800|female|2007
#> Adelie|Torgersen|40.3|18|195|3250|female|2007

Independent input and output delimiters

Read tab-separated input, write semicolons:

rush run --input-delimiter "\t" -D ";" 'head(df, 3)' cities.tsv
#> city;pop;province
#> Amsterdam;921402;Noord-Holland
#> Rotterdam;655468;Zuid-Holland
#> Utrecht;361924;Utrecht

Format flags

--input-format (-F)

Force a specific input format regardless of extension:

cp cities.tsv cities.txt
rush run -F tsv 'head(df, 3)' cities.txt
rm -f cities.txt
#> city,pop,province
#> Amsterdam,921402,Noord-Holland
#> Rotterdam,655468,Zuid-Holland
#> Utrecht,361924,Utrecht

--output-format (-O)

Force a specific output format:

rush run -O tsv 'head(df, 3)' penguins.csv
#> species  island  bill_length_mm  bill_depth_mm   flipper_length_mm   body_mass_g sex year
#> Adelie   Torgersen   39.1    18.7    181 3750    male    2007
#> Adelie   Torgersen   39.5    17.4    186 3800    female  2007
#> Adelie   Torgersen   40.3    18  195 3250    female  2007

Write as tab-separated even when piping (no output file):

rush run -O tsv 'head(df, 3)' penguins.csv | cat
#> species  island  bill_length_mm  bill_depth_mm   flipper_length_mm   body_mass_g sex year
#> Adelie   Torgersen   39.1    18.7    181 3750    male    2007
#> Adelie   Torgersen   39.5    17.4    186 3800    female  2007
#> Adelie   Torgersen   40.3    18  195 3250    female  2007

Header control

--no-header (-H)

Suppress the header on both input (no column names in the file) and output:

echo -e "1,Alice\n2,Bob\n3,Carol" | rush run -H 'df'

--no-input-header

Read a file without a header row, but still include a header in the output:

echo -e "1,Alice\n2,Bob\n3,Carol" | rush run --no-input-header 'df'

--no-output-header

Read normally but suppress the header in the output:

rush run --no-output-header 'head(df, 3)' penguins.csv | cat
#> Adelie,Torgersen,39.1,18.7,181,3750,male,2007
#> Adelie,Torgersen,39.5,17.4,186,3800,female,2007
#> Adelie,Torgersen,40.3,18,195,3250,female,2007

--names

Provide explicit column names (comma-separated). Implies --no-input-header:

echo -e "1,Alice\n2,Bob\n3,Carol" | rush run --names "id,name" 'df'

Limiting output with --head

Limit output to the first N rows:

rush run --head 5 'df' penguins.csv
#> species,island,bill_length_mm,bill_depth_mm,flipper_length_mm,body_mass_g,sex,year
#> Adelie,Torgersen,39.1,18.7,181,3750,male,2007
#> Adelie,Torgersen,39.5,17.4,186,3800,female,2007
#> Adelie,Torgersen,40.3,18,195,3250,female,2007
#> Adelie,Torgersen,36.7,19.3,193,3450,female,2007
#> Adelie,Torgersen,39.3,20.6,190,3650,male,2007

Works with any output format:

rush run --head 3 -O tsv 'df' penguins.csv
#> species  island  bill_length_mm  bill_depth_mm   flipper_length_mm   body_mass_g sex year
#> Adelie   Torgersen   39.1    18.7    181 3750    male    2007
#> Adelie   Torgersen   39.5    17.4    186 3800    female  2007
#> Adelie   Torgersen   40.3    18  195 3250    female  2007

Combined with SQL:

rush sql --head 3 "SELECT * FROM penguins ORDER BY body_mass_g DESC" penguins.csv
#> species,island,bill_length_mm,bill_depth_mm,flipper_length_mm,body_mass_g,sex,year
#> Gentoo,Biscoe,49.2,15.2,221,6300,male,2007
#> Gentoo,Biscoe,59.6,17,230,6050,male,2007
#> Gentoo,Biscoe,48.8,16.2,222,6000,male,2009