Skip to content

Instantly share code, notes, and snippets.

@ityonemo
Last active October 26, 2017 01:42
Show Gist options
  • Save ityonemo/0d2dad3b67e7c970f8205a67092d5273 to your computer and use it in GitHub Desktop.
Save ityonemo/0d2dad3b67e7c970f8205a67092d5273 to your computer and use it in GitHub Desktop.
expressive C++17 in Julia
(length(ARGS) < 4) && (println("error, insufficient arguments"); exit(1))
infile, column, replace, outfile = ARGS
function replace_column(idx)
(idx == 0) && (println("column name doesn’t exist in the input file"); exit(1))
mtx2 = copy(mtx)
mtx2[2:end,idx] = collect(Iterators.repeated(replace,size(mtx,1) - 1))
mtx2
end
try
global mtx = readcsv(infile)
catch
println("file missing")
exit(1)
end
length(mtx) == 0 && (println("input file missing"); exit(1))
size(mtx, 1) == 1 && writecsv(outfile, mtx)
mtx[1,:] |>
a -> findfirst(a, column) |>
replace_column |>
m -> writecsv(outfile, m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment