CSV 文件格式
我编写了一个 perl 脚本来输出一个文本文件,其中填充了我扫描到 Microsoft Excel 中的 IP 地址和端口。现在数据在 Excel 中,我的老板希望我以 csv 格式组织文件,例如
Server, port, protocol, random, random, random
ns1, 25, tcp, stuff, stuff, stuff
有人可以帮我解决这个问题吗?
代码:
#!/usr/bin/perl
$input = `Cat /cygdrive/c/Windows/System32/test11.txt | grep -v 'SYN Stealth'`;
chomp input;
$output =" /cygdrive/c/Users/bpaul/Desktop/194.csv ";
if (! -e "$output")
{
`touch $output`;
}
open (OUTPUTFILE, ">$output") || die "Can't Open file $output";
print OUTPUTFILE "$input\n";
close (OUTPUTFILE);
这是我的文件的一部分
Nmap scan report for 69.25.194.2 Host is up (0.072s latency). Not shown: 9992 filtered ports PORT STATE SERVICE 25/tcp open smtp
80/tcp open http
82/tcp open xfer
443/tcp open
https 4443/tcp closed
pharos 5666/tcp closed
nrpe 8080/tcp closed
http-proxy 9443/tcp closed tungsten-https
到目前为止,我的代码获取了我的txt文件并将其输出到excel,现在我需要像这样格式化数据:
所需的输出:
Server, port, protocol, random, random, random
ns1, 25, tcp, stuff, stuff, stuff
I wrote a perl script to output a text file filled with ip addresses and ports that i scanned into microsoft excel. Now that the data is in excel my boss wants me to organize the file in csv format such as
Server, port, protocol, random, random, random
ns1, 25, tcp, stuff, stuff, stuff
Can any one help me with this Please?
Code:
#!/usr/bin/perl
$input = `Cat /cygdrive/c/Windows/System32/test11.txt | grep -v 'SYN Stealth'`;
chomp input;
$output =" /cygdrive/c/Users/bpaul/Desktop/194.csv ";
if (! -e "$output")
{
`touch $output`;
}
open (OUTPUTFILE, ">$output") || die "Can't Open file $output";
print OUTPUTFILE "$input\n";
close (OUTPUTFILE);
Here is a piece of my file
Nmap scan report for 69.25.194.2 Host is up (0.072s latency). Not shown: 9992 filtered ports PORT STATE SERVICE 25/tcp open smtp
80/tcp open http
82/tcp open xfer
443/tcp open
https 4443/tcp closed
pharos 5666/tcp closed
nrpe 8080/tcp closed
http-proxy 9443/tcp closed tungsten-https
So far my code took my txt file and outputted it to excel now I need to format the data like this:
Desired Output:
Server, port, protocol, random, random, random
ns1, 25, tcp, stuff, stuff, stuff
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您说
ns1
时指的是69.25.194.2
。用法:
Text::CSV_XS
更新:替换为硬编码
ns1
带有扫描机器的地址。更新:将通用用法替换为 OP 将使用的内容。
I'm assuming you meant
69.25.194.2
when you saidns1
.Usage:
Text::CSV_XS
Update: Replaced hardcoded
ns1
with address of scanned machine.Update: Replaced generic usage with what the OP would use.