#!/usr/bin/perl
use strict;
my $f1 = shift;
my $f2 = shift;
open(F1,"<",$f1) || die "couldn't open '$f1' for read: $!\n";
open(F2,"<",$f2) || die "couldn't open '$f2' for read: $!\n";
# set the input record separator (IRS) to '@'
$/='@';
# Normally the IRS is found at the END of a record, but your input
# files START with the input record separator, so we need to throw
# away the first (bogus) input record (i.e. everything from the start
# of the files to the first @ characters in them. in other words, the
# first @ characters in both files.)
my $junk = <F1>;
$junk = <F2>;
while (!eof(F1) && !eof(F2)) {
my @record1 = split(/\n/, <F1>);
my @record2 = split(/\n/, <F2>);
printf "%s%s\n", $/, $record1[0]; # prepend the IRS
printf "%s%s\n", substr($record2[1],0,4), $record1[1];
printf "%s\n", $record2[2];
printf "%s%s\n", $record2[3], $record1[3];
};
close(F1);
close(F2);
Это открывает оба файла для чтения и устанавливает переменную разделителя входных записей Perl $/
в символ @
.
Затем, пока оба файла не достигли EOF, он считывает запись из каждого файла, разбивая записи на массивы (с использованием новой строки \n
в качестве разделителя ), а затем выводит объединенные записи, как указано.
Обратите внимание, что массивы perl начинаются с 0, а не с 1 -, поэтому, например, $record1[0]
— это первая строка записи из файла1.
Сохраните скрипт в файл (, например. hassan.pl
), сделайте его исполняемым с помощью chmod +x hassan.pl
и запустите, как показано ниже:
Пример вывода:
$./hassan.pl file1.txt file2.txt
@NB551168:120:HTKN2BGX5:1:11101:3598:1051 2:N:0:NATC
NATCCAATCTCTAAAGTTT
+
#EEEAA/A/EEEE///EEE
@NB551168:120:HTKN2BGX5:1:11101:24202:1051 2:N:0:NTCG
NTCGTGAGACCGGGTGTTG
+
#EEEAAAAAAEEE///<AA
@NB551168:120:HTKN2BGX5:1:11101:4381:1051 2:N:0:NCTT
NCTTGCTACTCCTAAGGCA
+
#EEAA////6/////EE//
(Я проверил с помощью diff
, что этот вывод точно соответствует желаемому результату ).
использовать возврат
numeric ()
{
# compute k either 1 or 0 || return 1
echo "$k"
return 0
}
numeric || exit 1