Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

for Anuj@stackoverflow

View split_anuj.bash
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# Related comments: http://stackoverflow.com/questions/12515584/splitting-large-file-into-small-multiple-files-based-on-the-column-concatenation#comment16849432_12515771
# Related chat: http://chat.stackoverflow.com/rooms/16930/discussion-between-shawn-chin-and-anuj
 
 
# the following splits a file into new files that are named based on fields 2, 3 and 5
# The first line of the input file is used as a header for all new files created
 
sort -k2,3 -k5,5 -t, infile.txt | awk -F, '
FNR == 1 { # if first line
header = $0; # store line as header
}
FNR != 1 { # NOT first line
filename = $2"_"$3"_"$5;
if (filename != prev) { # new label found
print header > filename # create new file with header
prev = filename # store
}
print >> filename # append current line to file
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.