Created
April 23, 2020 15:51
-
-
Save lululau/a1a4dc3351549c94d6dd9b963259f4a2 to your computer and use it in GitHub Desktop.
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
ruby -i.bak -F, -ane ' | |
p=$F[2].gsub(/省|市|自治区/, ""); | |
c=$F[3].gsub(/市|自治./, ""); | |
co=$F[4].gsub(/市|区|县|自治./, ""); | |
$F[1]=$F[2]+$F[3]+$F[4]+$F[1].gsub(Regexp.new("^.*(%s|%s|%s)"%[$F[2],$F[3],$F[4]]), "").gsub(Regexp.new("^.*(%s|%s|%s)"%[p,c,co]), ""); | |
$F[-1].chomp! | |
p1=$F[-3].gsub(/省|市|自治区/, ""); | |
c1=$F[-2].gsub(/市|自治./, ""); | |
co1=$F[-1].gsub(/市|区|县|自治./, ""); | |
$F[-4]=$F[-3]+$F[-2]+$F[-1]+$F[-4].gsub(Regexp.new("^.*(%s|%s|%s)"%[$F[-3],$F[-2],$F[-1]]), "").gsub(Regexp.new("^.*(%s|%s|%s)"%[p1,c1,co1]), ""); | |
puts $F.join(",");' query-hive-539733.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment