Related to Converting Height Measurements from Imperial to Metric units but with a different approach.
I've got a data set where there are a number of values with mixed units, particularly measuring height in both Imperial and Metric units. Additionally, for whatever reason, said Imperial measurements contain an excess of quotation marks.
I had thought that, instead of performing a conversion, a mass find-replace might work, as the heights of people are relatively constrained. For example, someone who is 5' 3" is 160.02cm so it's possible to just find all of one and replace it with another.
Consider this row in the data set test.csv
"Female","Hispanic",25,"5' 11"""
I'd like to replace "5' 11""" with "180.34".
I've tried sed -i 's#"5' 1"""#"180.34"#g' test.csv
but the only resulting output is a >
character in my terminal window, which suggests I've done something wrong, but can't quite figure out what. Is there something I'm missing to deal with the excess quotation marks?
The easiest is to <double-quote> your sed-string and escape your <double-quotes> in this case:
sed -i "s|\"5' 1\"\"\"|\"180.34\"|g" test.csv