将perl脚本文本修改为csv
您好,我编写了一个 perl 脚本来将带有端口扫描的文本文件输出到 Excel,现在我需要格式化该文本文件,以便在打印到 Excel 时它采用 csv 格式。比如像这样 服务器、端口、协议、状态 69.25.194.14, 25, tcp, http
这是我的代码,希望你们可以修改,到目前为止的代码将txt文件输出到excel,这很好,现在我只需要修改它,以便它可以在其中以csv格式显示它文本文件并将txt文件输出到excel :
$input = `Cat /cygdrive/c/Windows/System32/test11.txt | grep -v 'SYN Stealth' |grep -v'Discovered'`;
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);
这是我的 txt 文件的一部分,
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
有人可以修改我的代码吗?谢谢!
Hi I wrote a perl script to output a text file with port scans to excel now I need to format the text file so that when it prints to excel it's in csv format. Like this for example
Server, port, protocol, state
69.25.194.14, 25, tcp, http
Here is my code that I hope you guys could modify, The code so far outputs the txt file to excel which is good now I just need it modified so that it can display it in csv format within the text file and output the txt file to excel
:
$input = `Cat /cygdrive/c/Windows/System32/test11.txt | grep -v 'SYN Stealth' |grep -v'Discovered'`;
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 txt 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
Could anybody please modify my code. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一旦你弄清楚你想要什么列(我无法从你的问题中看出),我会看看
Text::CSV::print
用于输出。Once you figure what you want in what columns (I can't tell from your question), I'd look at
Text::CSV::print
for output.这很接近,但输入需要更多过滤。
This is close but the input needs more filtering.