Skip to content

Instantly share code, notes, and snippets.

@lululau
Created April 23, 2020 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lululau/a1a4dc3351549c94d6dd9b963259f4a2 to your computer and use it in GitHub Desktop.
Save lululau/a1a4dc3351549c94d6dd9b963259f4a2 to your computer and use it in GitHub Desktop.
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