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.


Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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