我正在尝试解压缩文件并计算文件中的匹配字符,之后我需要根据文件名连接文件。我成功实现了前两步,但我面临的问题是实现第三个目标。这是我正在使用的脚本。
#! use/bin/perl
use strict;
use warnings;
print"Enter file name for Unzip\n";
print"File name: ";
chomp(my $Filename=<>);
system("gunzip -r ./$Filename\*\n");
print"Enter match characters";
chomp(my $match=<>);
system("grep -c '$match' ./$Filename/* > $Filename/output");
open $fh,"/home/final_stage/test_(copy)";
if(my $file="sra_*_*_*_R1")
{
print $file;
}
system("mkdir $Filename/R1\n");
system("mkdir $Filename/R2\n");
基于&#34; sra_ _ _ _R1&#34;文件名匹配我必须连接并将其放在R1文件夹和&#34; sra _ _ _ _R2&#34;文件名R2文件夹。 帮我完成这项工作,欢迎所有建议!!!!!
答案 0 :(得分:0)
#!/usr/bin/perl
use strict;
use warnings;
use Path::Class;
use autodie; # die if problem reading or writing a file
my $dir = dir("/tmp"); # /tmp
my $file = $dir->file("file.txt");# Read in the entire contents of a file
my $content = $file->slurp();#
openr() returns an IO::File object to read from
my $file_handle = $file->openr(); # Read in line at a timewhile
( my $line = $file_handle->getline() )
{
print $line;
}
享受你的一天!!!!