Question

How to Arrange string data if both data have different spellings

I’ve been given a task to sort 1400 city names which has wrong spellings. with another data which has the right spellings. I want the result to be shown as the right and wrong data alligned together next to each other.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

It would really depend on the data, but what you could do is try and use the following Bash script:

#!/bin/bash

# A file containing the city list with the wrong names:
wrong_names=wrong.txt

# A file containing the city list with the right names:
right_names=right.txt

# Sort the files:
wrong_names_sorted=$(cat ${wrong_names} | sort > wrong_names_sorted.txt)
right_names_sorted=$(cat ${right_names} | sort > right_names_sorted.txt)

# Compare the two sorted files side by side:

sdiff ${wrong_names_sorted} ${right_names_sorted}

Hope that this helps!

Best,

Bobby