我有以下格式的CSV文件
902610747280285697, possible future hurricaneirma analog 1995\xC2\xA02003\xC2\xA02004\xC2\xA02008 2010 til east leeward doubtful afterward invest93l
902611695239094277, midlevel ridge push invest93l future hurricaneirma wsw ridge east leave som
902642953373577216, midlevel ridge push invest93l future hurricaneirma wsw ridge east leave som
902711459561525248, midlevel ridge push invest93l future hurricaneirma wsw ridge east leave som
902755305158782976, 12z ecmwf setup support major strike east coast high east deep uul west hurricaneirma
902772740507275265, possible future hurricaneirma analog 1995\xC2\xA02003\xC2\xA02004\xC2\xA02008 2010 til east leeward doubtful
902777486186086400, future hurricaneirma satellite look impressive tropicaldepression10 24 hour
903355611810852867, hurricaneirma think f ***
903355689455804416, hurricaneirma tropics weather
903411347337162752, hurricaneirma shiiiiiiitty t *** im possibly wrong
903411365607591936, hurricaneirma 3000 mile cat 3 hurricane watch closely
903989185845088257,
如何删除像*,\ xC2 \ xA02003 \ xC2 \ xA02004 \ xC2 \ xA0这样的字符,以及最后一行可能会在Scala处理中抛出错误的空行。我需要维护CSV结构以与以前相同的方式,但要求删除这些。
请帮我在shell脚本中实现这个目的? 再次感谢您,因为我是shell脚本的新手
编辑:
请告诉我如何纠正损坏的行(没有','),如
902755305158782976, 12z ecmwf setup support major strike east coast high east deep uul west hurricaneirma
902777486186086400, future hurricaneirma satellite look impressive tropicaldepression10 24 hour
903355611810852867 hurricaneirma think
903355611810852868 hurricagggneirma think
答案 0 :(得分:2)
您可以使用sed
,但我很确定,您可能无法获得100%的结果。您应该使用您正在处理的文件的本机工具来获得所需格式的结果。无论如何,下面是我的尝试:
$ sed -E '/^[^,]*$/d;/^[0-9]+, *$/d;s/ \*+ */ /;s/\\[xX][^\ ,]*//g' case_file_48246326
<强>输出强>
902610747280285697, possible future hurricaneirma analog 1995 2010 til east leeward doubtful afterward invest93l
902611695239094277, midlevel ridge push invest93l future hurricaneirma wsw ridge east leave som
902642953373577216, midlevel ridge push invest93l future hurricaneirma wsw ridge east leave som
902711459561525248, midlevel ridge push invest93l future hurricaneirma wsw ridge east leave som
902755305158782976, 12z ecmwf setup support major strike east coast high east deep uul west hurricaneirma
902772740507275265, possible future hurricaneirma analog 1995 2010 til east leeward doubtful
902777486186086400, future hurricaneirma satellite look impressive tropicaldepression10 24 hour
903355611810852867, hurricaneirma think f
903355689455804416, hurricaneirma tropics weather
903411347337162752, hurricaneirma shiiiiiiitty t im possibly wrong
903411365607591936, hurricaneirma 3000 mile cat 3 hurricane watch closely