DEV Community

Cover image for TIL about paste
Jonathan Lacanlale
Jonathan Lacanlale

Posted on

6 1

TIL about paste

In a large chunk of my work, I've had to deal with cleaning and combining multiple data files. Today I learned that bash has a simple command called paste. Here's what the manpage says
alt-text
Now that's a lot to digest but how is it useful? Well I have two files here, fileone.csv and filetwo.csv

alt-text
alt-text

I generally don't like wasting lines of code to read in multiple data frames so I usually want to combine them. Now, it takes more than just a simple paste fileone.csv filetwo.csv > combined.csv to combine them since the output is this:
alt-text
This is because paste merges the files. No replacing character is specified. For my work, I use

paste -d"\n" fileone.csv filetwo.csv > combined.csv

to achieve the output I desire:
alt-text
Now all I have to do is delete a single row. Yes you may have multiple csv's combined, but your header row gets moved to the top regardless, making deletion much easier. Extra ease if you're using Vim :^)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more