Last active
November 28, 2018 05:29
-
-
Save a2ikm/f85480eb055434868a699d9de87a565e to your computer and use it in GitHub Desktop.
Usage: ruby reverse_tsv.rb <tsv> [<offset>]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "csv" | |
path = ARGV[0] | |
offset = ARGV[1] ? ARGV[1].to_i : 1 | |
opts = {} | |
opts[:col_sep] = "\t" if path.end_with?(".tsv") | |
rows = CSV.read(ARGV[0], opts) | |
s = CSV.generate(col_sep: "\t") do |csv| | |
rows.each do |row| | |
new_row = [] | |
offset.times do | |
new_row << row.shift | |
end | |
new_row += row.reverse | |
csv << new_row | |
end | |
end | |
print s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment