我有一个这样的csv文件"5478",a,56.40,-0.40 ,55.50,57.50,55.30,56.74,"862,971","48,962,460","695",56.40,56.60,"127,474,332",56.40,60.30,52.50"5480",b,21.90,-0.25 ,21.80,22.00,21.80,21.87,"1,598,041","34,950,597","590",21.90,21.95,"199,097,830",21.90,23.40,20.40"70462P",c,0.01,-0.01 ,0.01,0.01,0.01,0.01,"99,000","990","1",0.01,0.06,"5,000,000",0.01,0.31,0.01"70465P",d, ---,--- ,---,---,---,0.02,"0","0","0",0.01,0.03,"20,000,000",0.02,0.32,0.01"8935",bt,5.02,-0.02 ,4.95,5.19,4.92,5.05,"949,102","4,791,070","290",5.02,5.07,"201,902,107",5.02,5.37,4.671333,tnd,21.40,-0.60 ,22.00,22.20,21.20,21.52,"1,519,292","32,692,804","631",21.40,21.50,"102,525,625",21.40,22.85,19.95我想检查第一列(如果超过4位数字),然后删除该行,例如,第二行和第三行将被删除。我该怎么做呢?多谢ps2这是从股票中心下载的股票信息,但是我发现格式最近发生了变化,之前的格式是最后一行,第一列没有引号“”,是否可以过滤这两种格式?还是我应该处理这两种情况?
3 回答
交互式爱情
TA贡献1712条经验 获得超3个赞
这是一个sed
解决方案:
sed -e '/^"[0-9]\{5\}/d' in-file > out-file
您还可以使用-i
选项进行就地替换:
sed -i -e '/^"[0-9]\{5\}/d' file
潇湘沐
TA贡献1816条经验 获得超6个赞
不确定您要使用哪种语言,因为您标记了awk并在标签中添加了sed,但是您可以简单地使用grep:
egrep '^\"[0-9]{1,4}\"' file.txt
墨色风雨
TA贡献1853条经验 获得超6个赞
awk
awk -F, '$1~ /^\"[0-9][0-9]?[0-9]?[0-9]?\"$/' file
GNU sed
sed '/^\"[0-9]\{1,4\}\"/!d' file
添加回答
举报
0/150
提交
取消