我有一个如下所示的数据文件:
xyz123 2.000 -0.3974 0.0 hij123
6.0 lmn123
8.7 efg123
13.9 uvw123
28.5 rst123
abc123 10.000 0.1943 0.0 wxy123
10.7 xyz123
19.9 pqr123
20.6 stu123
20.6 klm123
def123 50.000 -0.2595 19.2 jkl123
26.1 stu123
27.1 def123
27.1 ghi123
27.6 abc123
* uvw123 15.000 -0.3635
lmn123 40.000 -0.3695 19.2 jkl123
26.1 stu123
27.1 def123
27.1 ghi123
27.6 abc123
我需要将其转换为:
xyz123,2.000,-0.3974,0.0,hij123
xyz123,2.000,-0.3974,6.0,lmn123
xyz123,2.000,-0.3974,8.7,efg123
xyz123,2.000,-0.3974,13.9,uvw123
xyz123,2.000,-0.3974,28.5,rst123
abc123,10.000,0.1943,0.0,wxy123
abc123,10.000,0.1943,10.7,xyz123
abc123,10.000,0.1943,19.9,pqr123
abc123,10.000,0.1943,20.6,stu123
abc123,10.000,0.1943,20.6,klm123
def123,50.000,-0.2595,19.2,jkl123
def123,50.000,-0.2595,26.1,stu123
def123,50.000,-0.2595,27.1,def123
def123,50.000,-0.2595,27.1,ghi123
def123,50.000,-0.2595,27.6,abc123
* uvw123,15.000,-0.3635,
lmn123,40.000,-0.3695,19.2,jkl123
lmn123,40.000,-0.3695,26.1,stu123
lmn123,40.000,-0.3695,27.1,def123
lmn123,40.000,-0.3695,27.1,ghi123
lmn123,40.000,-0.3695,27.6,abc123
如何使用 Python 或 AWK 或 sed 做到这一点?
更新:因此,如果您注意到输入数据中有一行看起来像“ uvw123 15.000 -0.3635 ”,并且当我使用来自 aix 的 python 代码时,该行会变得混乱。有没有办法修改您的代码并正确输出我展示的行?