我需要使用外部数据,一个纯文本文件,其中包含要在Perl中处理的数据(我正在学习这种语言).
{NAME}
orga:21:12348:oragnisation
serv:22:12348:service
{NAME-END}
{DATA}
palm:data:fluid:147
rose:data:fluid:149
{DATA-END}
{OTHER}
palm:data:fluid:147
rose:data:fluid:149
germ:data:fluid:189
{OTHER-END}
Run Code Online (Sandbox Code Playgroud)
如何读取此文件并将每个部分存储在数组中(部分已知且在{xxxx}和之间分隔{xxxx-END}.部分中的每个数据都转换为列表并存储在数组中.我希望有这样的内容,例如:
@name = ( ("orga","21","12348","organisation"), ("serv","22","12348","service") )
Run Code Online (Sandbox Code Playgroud) 有两个以关联数组(key = value)的形式写的文件,如:
档案A:
banana=yellow
kiwi=green
tomato=red
Run Code Online (Sandbox Code Playgroud)
文件B:
banana=dislike
tomato=like
pear=like
Run Code Online (Sandbox Code Playgroud)
我想知道比较他们的密钥的最佳方法(在速度方面):
A对抗B:
kiwi=green
Run Code Online (Sandbox Code Playgroud)
B对阵A.
pear=like
Run Code Online (Sandbox Code Playgroud)
双向
kiwi=green
pear=like
Run Code Online (Sandbox Code Playgroud)
我宁愿不使用循环,因为这些文件可能很大.
我有一个大文本文件,我想从中删除另一个文本文件中的一些行.似乎sedUnix shell 中的命令是一个很好的方法.但是,我无法弄清楚要使用哪些标志..
database.txt:
this is line 1
this is line 2
this is line 3
this is line 4
this is line 5
Run Code Online (Sandbox Code Playgroud)
lines_to_remove.txt
this is line 1
this is line 3
Run Code Online (Sandbox Code Playgroud)
what_i_want.txt
this is line 2
this is line 4
this is line 5
Run Code Online (Sandbox Code Playgroud) 如何替换文件中以文字开头aaa的行我不知道该行的位置.
files.txt:
sadasd_dsada = (aa,bb,cc)
aaa = (aa,bb,cc)
sadasd_dsada = (aa,bb,cc)
Run Code Online (Sandbox Code Playgroud)
更换:
aaa = (aa,bb,cc)
Run Code Online (Sandbox Code Playgroud)
对于:
aaa = (dd,ee,ff)
Run Code Online (Sandbox Code Playgroud) 我有这样的事情:
color_names = ('red', 'blue', 'orange', 'red')
Run Code Online (Sandbox Code Playgroud)
从上面的列表中我想做这样的事情:
colors = [(0, 'red'), (1, 'blue'), (2, 'orange')]
Run Code Online (Sandbox Code Playgroud)
每种颜色都应该是唯一的,这就是为什么我必须忽略第一个列表中的第二个"红色".我目前的解决方案有许多循环和条件.我正在寻找更好的解决方案.
我想使用命令linux粘贴两个文件paste(以及任何其他选项也将受欢迎)但增加第二行的行.更好地举个例子:
文件1
a
b
c
d
e
f
Run Code Online (Sandbox Code Playgroud)
文件2
1
2
3
4
5
6
7
8
9
10
11
12
Run Code Online (Sandbox Code Playgroud)
我想创建file3为:
a 1
b 3
c 5
d 7
e 9
f 11
Run Code Online (Sandbox Code Playgroud) 我在这里有时间使用我的语法:我有3个文件,其中包含各种内容file1 file2 file3(100多行).我试图将它们合并在一起,但只应合并每个文件的第一行.重点是使用一行bash代码:
sed -n 1p file1 file2 file3仅返回file1的第一行
我有一个如下所示的文件,我想删除第四列中没有任何值的行.
Experiment Replica Module Mean
General1 0 scenario.host[229].app
General1 1 scenario.host[229].app 0.00235355
General1 2 scenario.host[229].app
General1 3 scenario.host[229].app 0.0783413
General1 4 scenario.host[229].app
General3 0 scenario.host[229].app
General3 1 scenario.host[229].app 0.540335
General3 2 scenario.host[229].app
General3 3 scenario.host[229].app
General3 4 scenario.host[229].app
General1 0 scenario.host[229].app
Run Code Online (Sandbox Code Playgroud) 我目前正在解析gcc像的错误日志
main.c:5:1: warning: data definition has no type or storage class [enabled by default]
main.c:8:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
main.c in function 'TryAdddition()'
main.c:24:1: warning: data definition has no type or storage class [enabled by default]
main.c:24:10: warning: data definition has no type or storage class [enabled by default]
Run Code Online (Sandbox Code Playgroud)
5,8,24,24是发生错误或警告的行号.我需要用数字+10替换这些数字,即: 15,18,34,34.
但是并非每条线都是错误或警告线.
我有一个配置文件,其内容如下:
db.path=/home/kpmg/test/dbfiles/dbone.db
db.connection.timeout=500000
server.url=http://a.b.c.d:8033/plain/httpds?
output.file.path=/home/kpmg/test/dbfiles/
log.file.path=/home/kpmg/test/dbfiles/
log.level=DEBUG
Run Code Online (Sandbox Code Playgroud)
我需要从server.url行中提取ip地址.我通过阅读示例和文档尝试使用几个awk命令,但无法正确使用它.