Last active
March 23, 2016 03:31
-
-
Save Nikita240/98bcebb33c919a3f5c25 to your computer and use it in GitHub Desktop.
Splits a Name column in a .csv file into FirstName and LastName
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
# *******************************USAGE******************************* | |
# cat names.csv | ./name.sh > names-processed.csv | |
target_col=3 | |
new_title="FirstName,LastName," | |
#pass the header line through the buffer first | |
read header | |
title=$(echo $header | sed -r "s/([^,]*,){$target_col}.*$/\1/") | |
echo $header | sed -r "s/$title/$new_title/" | |
#split name into Fname and Lname | |
while read row | |
do | |
name=$(echo $row | sed -r "s/([^,]*,){$target_col}.*$/\1/") | |
split_name=$(echo $name | sed -r "s/^(\S+)\s(.*)/\1,\2/") | |
echo $row | sed -r "s/$name/$split_name/" | |
done | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment