F1.txt
tom a b c d e boy
bob a b c sun
harry a c d e girl
结果
F2.txt
tom1 a1 b1 c1 d1 e1 boy1
tom2 a2 b2 c2 sun2
tom3 a3 c3 d3 e3 girl3
大家好,我对 Perl 还很陌生,你能帮我解决我的这个新问题吗?我有一个文件 F1.txt
,我的工作是根据行号在文件中的每个字符串后面分配数字,如上面的示例所示。到目前为止,我已经成功地使用 Perl 单行代码为每一行分配了一个编号
perl -pe '$_= ++$a." $_" if /./'
最佳答案
也许如下:
perl -pe 's/(?<=\w)\b/$./g;'
关于perl - 如何为文件中存在的每个字符串分配行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11842321/