Created
July 17, 2015 00:03
-
-
Save unxmaal/1992f34fdcbdb41ec2a6 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
_filename=$1 | |
_outputfile="frobnicated" | |
#For each file: | |
# get a list of non-unique ids | |
_non_unique_ids=$(cut -d',' -f1 "${_filename}" | sort | uniq -d) | |
# | |
# next, split your file into 2 piles | |
# use grep -v -F here. -F lets you use your nui's as a single big filter. | |
# This works even for monstrous files. | |
_unique_entries=$(grep -v -F "${_non_unique_ids}" "${_filename}") | |
_dupe_entries=$(grep -F "${_non_unique_ids}" "${_filename}") | |
# dump your unique entries to a file | |
echo "$_unique_entries" > "$_outputfile" | |
# just for testing, so you can see for yourself | |
echo "###### below were dupes" >> "$_outputfile" | |
# pick only the first entry that has a dupe ID | |
for _dupe in $_non_unique_ids ; do | |
# if you want to use something other than just grabbing the first dupe | |
# entry, you'll have to put it here. | |
_match=$(grep "${_dupe}" <<< "${_dupe_entries}" | head -n1) | |
if [[ -n "${_match}" ]] ; then | |
echo "${_match}" >> "$_outputfile" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment