What is the best way to remove distances in the following lines and output cdv format. Can this be done reasonably easily on the command line? I'd like to avoid having to write a full-blow script.Greece 282 km, Macedonia 151 km, Montenegro 172 km, Kosovo 112 kmCentral African Republic 797 km, Chad 1,094 km, Republic of the Congo 523The output would be:Greece,Macedonia,Montenegro,KosovoCentral African Republic,Chad,Republic of the Congo
Regex/pattern matching problem to extract data
sed;grep;awk;cut
No idea what kind if format is that cdv, but seems you only need to remove the digits followed by optional unit of measurement, then compact the spaces after the remaining commas:sed 's/ *[0-9]\+\(,[0-9]\+\)\?\( *km *\)\?//g;s/, \+/,/g' file.txtFor better readability, the same with extended regular expression (suitable for GNU sed):sed -r 's/ *[0-9]+(,[0-9]+)?( *km *)?//g;s/, +/,/g' file.txt