cat file
^QciProfilePredefined=qci2$ logicalChannelGroupRef QciTable=default,LogicalChannelGroup=2
EUtranCellTDD=.*-1[123456],UeMeasControl=1,ReportConfigA4=1$ a4ThresholdRsrp -140
Run Code Online (Sandbox Code Playgroud)
我想使用gensub()删除$ 1中最后一个逗号之前的内容(也删除逗号),而不影响其他包含逗号的列.
我的代码:
awk '{$1=gensub(/.*,/,"",1);print}' file
Run Code Online (Sandbox Code Playgroud)
输出:
LogicalChannelGroup=2 logicalChannelGroupRef QciTable=default,LogicalChannelGroup=2
ReportConfigA4=1$ a4ThresholdRsrp -140 a4ThresholdRsrp -140
Run Code Online (Sandbox Code Playgroud)
似乎ROW 2内容重复了"4ThresholdRsrp -140".
我预期的输出:
LogicalChannelGroup=2 logicalChannelGroupRef QciTable=default,LogicalChannelGroup=2
ReportConfigA4=1$ a4ThresholdRsrp -140
Run Code Online (Sandbox Code Playgroud) 以下是我的代码,请查看.
use strict;
my @people = qw{a b c d e f};
foreach (@people){
print $_,"$people[$_]\n";
}
Run Code Online (Sandbox Code Playgroud)
以下是输出,
[~/perl]$ perl test.pl
aa #why the output of $people[$_] is not same with $_?
ba
ca
da
ea
fa
Run Code Online (Sandbox Code Playgroud)
谢谢你的要求.
这是我的代码.我想打印出首都开头的所有线路:
while(<>){
if(/^[A-Z][a-z]+/){
print;
}
}
Run Code Online (Sandbox Code Playgroud)
test.txt:
Fred
fred
FRED
FreD
Run Code Online (Sandbox Code Playgroud)
执行命令后:
perl sc.pl test.txt
Fred
FreD
Run Code Online (Sandbox Code Playgroud)
为什么FreD打印出来?我有用[a-z]+,似乎+ 唯一匹配小写的期望最后一个?
我遇到的代码未能达到我的期望。详细信息如下:
a = ['name']
b = [('name=cheng',),('name=huang',),('name=pan',)]
Dict = {}
c = []
for i in range(0,3):
for j in range(0,1):
Dict[a[j]] = b[i][j]
c.append(Dict)
print(c)
>>> [{'name':'name=pan'},{'name':'name=pan'},{'name':'name=pan'}]
Run Code Online (Sandbox Code Playgroud)
i应该是什么
>>> [{'name':'name=cheng'},{'name':'name=huang'},{'name':'name=pan'}]
Run Code Online (Sandbox Code Playgroud)
那你能告诉我如何解决这个问题吗?