Hi,
I have four files named:
AS1.txt 
AS2.txt
AS3.txt
AS4.txt

The files contain the following text:
Example:

AS_CLI/ASDiagnostic/Diag>  7 phone 0773008619   
AS_CLI/ASDiagnostic/Diag>  7 phone 033008775    
AS_CLI/ASDiagnostic/Diag>  7 phone 087300936    
AS_CLI/ASDiagnostic/Diag>  7 phone 0773009111   
AS_CLI/ASDiagnostic/Diag>  7 phone 0773009701   
Status = FAILED
AS_CLI/ASDiagnostic/Diag>  7 phone 0773011572   
AS_CLI/ASDiagnostic/Diag>  7 phone 0773012844   
AS_CLI/ASDiagnostic/Diag>  7 phone 0773077029   
AS_CLI/ASDiagnostic/Diag>  7 phone 0773088133   
AS_CLI/ASDiagnostic/Diag>  7 phone 0773088195   
AS_CLI/ASDiagnostic/Diag>  7 phone 0773088317   
AS_CLI/ASDiagnostic/Diag>  7 phone 0773088539

I need to get the status, number (the line above the status) and the file that it came from in one line in one file.
I whole like to have one file that look like this:

0773009701 Status = FAILED AS1.txt
033009702 Status = FAILED AS2.txt
074309703 Status = FAILED AS3.txt
0723047012 Status = FAILED AS1.txt


Thanks in advance.

Hi erezz,
The program below will give you the output you want.
Please note that this program will be in the same directory with your text files or you might have to specify the path to these files yourself from the program. The result is saved to a file called output_file.txt

#!/usr/bin/perl
use warnings;
use strict;

open my $fhO, '>', 'output_file.txt'
  or die "can't open this file: $!";    #output file
foreach my $file (qw(AS1.txt AS2.txt AS3.txt AS4.txt)) {
open my $fh, '<', $file or die "can't open this file: $!";
local $/ = 'AS_';
while (<$fh>) {
    chomp;
    if (/status/i) {
        s{\n}{};
        if (/(\d{4,})(.+?)$/) {
            print $fhO $1, '  ', $2, '  ', $file, "\n";
        }
    }
}
close $fh or die "can't close this file:$!";
}
close $fhO or die "can't close this file:$!";
Comments
2 teez, Thank you very much for the quick response and for your help.

2 teez, Thank you very much for the quick response and for your help.

This question has already been answered. Start a new discussion instead.