如何使用简单的perl脚本重新排列txt文件的行?

问题描述 投票:-4回答:1

我的原始txt文件如下:

A "a,b,c"
B "d"
C "e,f"

我如何将其转换为:

A a
A b
A c
B d
C e
C f

我尝试过此

perl -ane '@s=split(/\,/, $F[1]); foreach $k (@s){print "$F[0] $k\n";}' txt.txt

它有效,但是如何消除“”

perl parsing text-parsing
1个回答
0
投票

您可以使用替换删除双引号

@s = split /,/, $F[1] =~ s/"//gr;

/r返回值,而不是就地更改值。

© www.soinside.com 2019 - 2024. All rights reserved.