在Unix中,如何从以下位置转换CSV文件:
"0.4542703549","PRO000029D00QWERT","1.562"
"0.1585242685","PRO000030K00QWERT","4.833"
"0.4542703549","PRO000031K00QWERT","0.011"
"0.8917651385","PRO000032K00QWERT","3.057"
到:
"29","0.4542703549","1.562"
"30","0.1585242685","4.833"
"31","0.4542703549","0.011"
"32","0.8917651385","3.057"
实际上,我想去掉第二列中的所有内容(数字1-9除外),然后交换第1列和第2列的位置。
提前谢谢你的帮助。。
最佳答案
使用sed时最简单
sed 's/\("[^"]*"\),"PRO0*\([0-9]\{1,\}\)[^"]*"/\"\2",\1/' YourFile
可供替代的
awk -F ',' -v 'quote="' '{print quote substr($2,5,6) + 0 quote "," $1 "," $3 }' YourFile
关于linux - Unix:过滤和处理CSV中的列数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33369650/