Bash Commands are Programming Too

I had a problem where I needed to get some files of fantasy golf names / salaries into a CSV file that I would be able to parse. I hadn’t downloaded them, and there was a guy on this chat room that we talk in who had, but he put them all 4 tournaments into one excel spreadsheet. When I tried to copy the necessary rows from google sheets to a text file, it copied them in a tab separated format, rather than the csv that I needed.

Despite it’s simplicity, there still is a little bit of overhead in writing a python script to read in the rows of the files, parse out the tabs, and then spit out a correctly formatted line. So I took a few minutes to see if I could find a way to do this from the command line. And turns out there is.

Thanks to the wonderful pipe operator, the following command

cat colonial/dk.tsv | tr "\\t" "," > draftkings.csv

spits out the input file, pipes that output over where the tabs into commas, then redirects the output into the csv file I want.

So before jumping straight to python or another scripting language, take a second and see if you can accomplish what you’re trying to do from the command line. I bet you’ll be pleasantly surprised.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s