I am looking for some hints, how I could achive a better, more elegant, efficient solution. So I've got a file containing a list of names.
Doe John del Super Mario van Hoppity Jenny van der Hupfburg Susi Smith-Osborne John Marc
John Doe Mario del Super Jenny van Happity Susi van der Hupfburg John Marc Smith-Osborne
As you can see, the sort order is "family name" followed by "name" and no specific delimiter (just spaces) seperating family name from name. What I want is first name than family name. In most cases the first word is the family name. In some cases, there is a prefix like "van" or the italian "del". To attach these prefixex to the family name, I want to replace the spaces with a dash - so they become on word (van-Hoppity, van-der-Hupfburg, etc.) and i can move the first word to the end of line,
My current sed solution is working, but the line is getting longer and longer with every new prefix found.
So i want to use awk, with a file containing the search patterns (prefix list) that should find the pattern in the names file and replace it.
so 2 files
pattern.txt containing the prefixes and the substitute replacement in the second field. Field seperator is ";"
del ;del- van der ;van-der- van ;van-
awk should use pattern.txt to search in names.txt and replace the found matches with the value of field 2 in pattern.txt
Any idea hints, suggestions?