DEV Community

Cover image for TIL about paste
Jonathan Lacanlale
Jonathan Lacanlale

Posted on

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 :^)

Top comments (0)