Perl:How to insert line in a file? - regex

I am reading from two files. I'm trying to insert a line from file2 to file1 whenever column 1 contents matches.
##FILE1
1 wr 5769 78670002 fqefq
3 wr 5769 78650003 hfhhg
5 wr 5769 88990001 dfdsv
##FILE2
1 Step1
3 Step3
5 Step5
Desired Output:
1 wr 5769 78670002 fqefq
Step1
3 wr 5769 78650003 hfhhg
Step3
5 wr 5769 88990001 dfdsv
Step5
Code tried:
my $rk="rk.log";
open(my $tt, "<$rk" ) or die "Could not open file $trk: $!";
while (<$tt>) {
if ($_ =~ /^(\d+)\s+wr\s+5769\s+(\w+)\s+\.*/gm) {
open(p1,"<$temp1") or die "Could not open file $temp1: $!";
while (my $newl = <p1>) {
my #fs1 = split " ", $newl;
if ($fs1[0] eq $1){
print "#fs1\n";
print "step $2\n";
} else {
print "#fs1\n";
}
}
}
}
close p1;
close $tt;
Above code doesn't giving the desired output. Can anyone suggest me better way to do it?
Update ##FILE2
2 Step1
4 Step3
6 Step5

Hopefully, a bit of pseudocode will be enough to get you on the right track.
Read file2 into a hash (where the key is the integer and the value is the whole line)
Open file1
Read file1 a line at a time
Print the line from file1
Extract the integer from the start of the line from line1
If that integer exists in your hash
Print the line from file2

I believe the simplest method would be to import the two files into separate strings, then create a loop which:
Finds match in file 1. (Include line breaks in your matches)
Appends match to third string.
Deletes match from file 1. (Replace with nothing)
Finds match from file 2. (Include line breaks in your matches)
Appends match to third string.
Deletes match from file 2.
This way you will sequentially order all of your matches from the two files into a string that you can export as a file.

This is works for me:
use Tie::File;
my $fle1 = $ARGV[0]; my $fle2 = $ARGV[1];
open(FL2, $fle2) || die "Couldn't read file $fle2\: $!\n";
my $flecnt2 = do { local $/; <FL2>; };
close(FL2);
my #array;
tie #array, 'Tie::File', $fle1 || die "Error: Couldn't read and write \"$fle1\" file: $!";
my $str = join "\n", #array;
$str=~s#^([^\s]+)\s(.+)$# my $fulcnt=$&;
if($flecnt2=~m/^$1\s+(.+)$/m)
{
$fulcnt .= "\n$&";
}
($fulcnt);
#egm;
#array = split/\n/, $str;
untie #array;

Related

How to compare each element of two different databases in text files using perl?

I am trying to compare each element of column 1 from one list (screens.txt) with any element of column 1 from the other list (new_list.txt) and if matched, print the whole row of the list (screens.txt) in a separate text file (matched.txt).
I managed to select the right columns but the output I am getting are the rows from the list (new_list.txt) instead of list (screens.txt) and only one hit was found so it looks like there is also a problem with a loop.
new_list.txt format => first_column->double_tab->the_rest
I am very new in perl programming. Any help would be very much appreciated!
Here is what I've go so far:
#!usr/bin/perl
use warnings;
$list = "new_list.txt";
$screens = "screens.txt";
$result = "matched.txt";
open (FA, "<$list") or die "Can't read source file $list: $!\n";
open (RES, ">$result") or die "Can't write on file $result: $!\n";
$n = 0;
$column = 10;
while ($line = <FA>) {
#description = split (' ', $line);
#ID = split ('\\t', $description[0]);
#print just first column from the list
# print "$ID[0]\n";
}
close (FA);
open (FA, "$screens") or die "Can't read source file $screens: $!\n";
while ($file = <FA>) {
#table = split (' ', $file);
#accession_no = split ('\ ', $table[0]);
# print the first column from the list
# print "$accession_no[0]\n";
}
open (FA, "<$list") or die "Can't read source file $list: $!\n";
while ($line = <FA>) {
print "$line\n";
#description = split (' ', $line);
#ID = split ('\\t', $description[0]);
if ($accession_no eq $ID[0]) {
$n = $n+1;
for ($i = 0; $i < $column; $i++) {
print RES "$file";
}
print "\n";
}
}
close (FA);
close (RES);
print "Hits found: $n\n";
Here is a sample of next_list.txt:
Q9UKA8 RCAN3_HUMAN 0
Q9UKA8-2 RCAN3_HUMAN 0
Q9UKA8-3 RCAN3_HUMAN 0
Q9UKA8-4 RCAN3_HUMAN 0
Q9UKA8-5 RCAN3_HUMAN 0
Q9GZP0 PDGFD_HUMAN 0
here is the input file from screens.txt:
Q9GZP0 GDLDLASEST Scaffold attachment factor B2 (SAF-B2) SAFB2
Q9UKA8-5 QKAFNSSSFN Ran GTPase-activating protein 1 (RanGAP1) RANGAP1
I'm interested in checking if Q9GZP0 and Q9UKA8-5 (first column)
from screens.txt are in first column of new_list.txt and if they
are then print the whole line/row from screens.txt.
Thank you in advance!
Minimal code to filter screens with power of map block
#!/usr/bin/perl
use strict;
use warnings;
my $input1 = 'new_list.txt';
my $input2 = 'screens.txt';
my %seen;
open my $fh1, "< $input1"
or die "Couldn't open $input1";
map{ $seen{$1} = $2 if /(\S+)\s(.*)/ } <$fh1>;
close $fh1;
open my $fh2, "< $input2"
or die "Couldn't open $input2";
map{ print if /(\S+)\s+(.*)/ and $seen{$1} } <$fh2>;
close $fh2;
Input: new_list.txt
Q9UKA8 RCAN3_HUMAN 0
Q9UKA8-2 RCAN3_HUMAN 0
Q9UKA8-3 RCAN3_HUMAN 0
Q9UKA8-4 RCAN3_HUMAN 0
Q9UKA8-5 RCAN3_HUMAN 0
Q9GZP0 PDGFD_HUMAN 0
Input: screens.txt
Q9GZP0 GDLDLASEST Scaffold attachment factor B2 (SAF-B2) SAFB2
Q9UKA8-5 QKAFNSSSFN Ran GTPase-activating protein 1 (RanGAP1) RANGAP1
Output:
Q9GZP0 GDLDLASEST Scaffold attachment factor B2 (SAF-B2) SAFB2
Q9UKA8-5 QKAFNSSSFN Ran GTPase-activating protein 1 (RanGAP1) RANGAP1
NOTE:
Linux -- Make the program executable with a command chmod og+x program.pl
Windows -- Run the program as perl program.pl
REDIRECT output into a file with a command:
Linux - program.pl > matched.txt
Windows - perl program.pl > matched.txt
See if this helps you:
#!/usr/bin/perl
use strict;
use warnings;
my $file1 = "file_pr1.txt";
my $file2 = "file_pr2.txt";
my $resulted_list = "result_list.txt";
my (#description, #ID, #data);
open (my $FA, "<$file1") or die "Can't read source file $file1: $!\n";
while (my $line = <$FA>) {
chomp($line);
#description = split (/\s+/, $line);
push (#ID, $description[0]);
}
close($FA);
my %params = map { $_ => 1 } #ID; #add each elements into hash
open (my $RES, ">$resulted_list") or die "Open as write error : $!\n";
open (my $FB, "<$file2") or die "Can't read source file $file2: $!\n";
while (my $line = <$FB>) {
chomp($line);
#data = split (/\s+/, $line);
print $RES $line."\n" if(exists($params{$data[0]})); #Write to result file
}
close($RES);

How to print lines in between two patterns?

I would like to print everything between lines #cluster t.# has ### elements (including this line) and #cluster t.#+1 has ### elements (preferably omitting this line) from my input file into corresponding numbered output files (clust(#).txt). The script thus far creates the appropriate numbered files, without any content.
#!/usr/bin/perl
use strict;
use warnings;
open(IN,$ARGV[0]);
our $num = 0;
while(my $line = <IN>) {
if ($line =~ /^\#cluster t has (\d+) elements/) {
my $clust = "full";
open (OUT, ">clust$clust.txt");
} elsif ($line =~ m/^\#cluster t.(\d+.*) has (\d+) elements/) {
my $clust = $1;
$num++;
open (OUT, ">clust$clust.txt");
print OUT, $_ if (/$line/ ... /$line/);
}
}
Update Re-arranged so that the version based on my final understanding of input comes first. Also edited for clarity.
Detect the line that starts the section to be written to its own file and open the suitable file; otherwise just write to the filehandle (that corresponds to the current output file).
An example input file, in my understanding, data_range.txt
#cluster t.1 has 100 elements
data 1
data 1 1
#cluster t.2 has 200 elements
data 2
#cluster t.3 has 300 elements
Print t.N and the lines following up to the next t.N, to a file clust(N).txt.
use warnings;
use strict;
my $file = shift || 'data_range.txt';
open my $fh, $file or die "Can't open $file: $!";
my $fh_out;
my $clustline = qr/\#cluster t\.([0-9]+) has [0-9]+ elements/;
while (<$fh>)
{
if (/$clustline/) {
my $outfile = "clust($1).txt";
open $fh_out, '>', $outfile or die "Can't open $outfile: $!";
}
print $fh_out $_;
}
For each line with #cluster a new file with the corresponding number is opened, closing the previous one since we use the same filehandle. All following lines, including that one, belong to that file and they are printed there.
The code above assumes that the first line in the file is a #cluster line, and that all lines in this file belong to one of output files. If this may not be so then we need to be more careful: (1) use a flag for when the writing starts and (2) add a branch that allows to skip lines.
my $started_writing = 0;
my $clustline = qr/\#cluster t\.([0-9]+) has [0-9]+ elements/;
while (<$fh>)
{
if (/$clustline/) {
my $fout = "clust($1).txt";
open $fh_out, '>', $fout or die "Can't open $fout for writing: $!";
$started_writing = 1;
}
elsif (not $started_writing) { # didn't get to open output files yet
next;
}
elsif (/dont_write_this_line/) { # condition for lines to skip altogether
next;
}
print $fh_out $_;
}
All of this assumes that a #cluster line cannot repeat with the same number. You'd lose output data if that happened, so add a test if you aren't sure of your input (or open output files in append mode).
With either we get output clust(1).txt
#cluster t.1 has 100 elements
data 1
data 1 1
and clust(2).txt
#cluster t.2 has 200 elements
data 2
and clust(3).txt with the #cluster t.3 line.
Original version, with the initial understanding of input and requirements
The range operator is nearly tailor made for this. It keeps track of its true/false state across repeated calls. It turns true once its left operand evaluates true and stays that way until the right one is true, after which it is false, so on the next evaluation. There is more to it, please see the docs.
Made-up input file data_range.txt
#cluster t.1 has 100 elements
#cluster t.2 has 200 elements
#cluster t.3 has 300 elements
#cluster t.4 has 400 elements
#cluster t.5 has 500 elements
Print everything between marker-lines 2 and 4, including the starting line but not the ending one.
use warnings;
use strict;
my $file = 'data_range.txt';
open my $fh, $file or die "Can't open $file: $!";
# Build the start and end patterns
my $beg = qr/^\#cluster t\.2 has 200 elements$/;
my $end = qr/^\#cluster t\.4 has 400 elements$/;
while (<$fh>)
{
if (/$beg/ .. /$end/) {
print if not /$end/;
}
}
This prints lines 2 and 3. The .. operator turns true once the line ($_) matches $beg and is true until a line matches $end. After that it is false, for the next line. Thus it ends up including both start and end lines as well. So we also test for the end marker, and not print if we have that line.
If you would rather use the literal marker lines you can test strings for equality
my $beg = q(#cluster t.2 has 200 elements);
my $end = q(#cluster t.4 has 400 elements);
while (my $line = <$fh>)
{
chomp($line);
if ($line eq $beg .. $line eq $end) {
print "$line\n" if $line ne $end;
}
}
This works the same way as the example above. Note that now we have to chomp since the newline would foil eq test (and then we add \n for printing).
I have a more concise way to provide :
perl -ne 'print if /^foo/ .. /^base/' file.txt
Sample input
Lorem ipsum dolor
sit amet,
consectetur adipiscing
foo
bar
base
elit,
sed do
Output
foo
bar
base

Read two files and substitute a pattern in one file with data from the other file

I am running a perl script, which takes data from first file, match a pattern in second file, and replace with the data (first file) when match is found.
When I run my script, no replacement occurs in the second file. I am working on windows.
use strict;
use warnings;
my ($value1,$value2);
open(file1, "data1.txt") or die "Cannot open file.\n";
open(file2, "data2.txt") or die "Cannot open file.\n";
while (<file1>) {
$value1 = $_;
chomp($value1);
my #parts = split(/ +/, $value1);
$value2 = <file2>;
$value2 =~ s/ threshold1/ $parts[0]/;
$value2 =~ s/ threshold2/ $parts[1]/;
$value2 =~ s/ threshold3/ $parts[1]/;
}
close(file1);
close(file2);
File 1
10
20
30
File 2
a=1 b=2 c=3
d=4 e=5 f=6
g = threshold1 h=7 i=8
lines
lines
j= 9 k=11
l = threshold2
lines
lines
m = threshold3
lines
lines
I need to replace threshold1 , threshold2, threshold3 in second file, with values from the first file.
Here are some modifications to your code, which should now work as you want:
use strict;
use warnings;
Use a lexically scoped 3 argument open (which is now recommended practise):
open my $file1, '<', '1.txt' or die "Cannot open file\n";
open my $file2, '<', '2.txt' or die "Cannot open file\n";
Then add each of your lines in file1 to the end of the array #parts:
my #parts;
push #parts, $_ while(<$file1>);
chomp(#parts);
Then simply read file2 line by line and substitute appropriately, then you can see what's happened to each line by printing each line ($_) to STDOUT:
while (<$file2>) {
chomp;
s/threshold1/$parts[0]/;
s/threshold2/$parts[1]/;
s/threshold3/$parts[2]/; # I assume you want '30' here?
print "$_\n";
}
So the output is:
a=1 b=2 c=3
d=4 e=5 f=6
g = 10 h=7 i=8
lines
lines
j= 9 k=11
l = 20
lines
lines
m = 30
lines
lines
Let me know if this is indeed what you're trying to do and I can explain the changes I've made
The problem is that you are reading lines from both files and processing them in pairs. So line one of the data file will take values from line one of the threshold file, line two from line two of the threshold file etc. And the loop will end when you reach the third line of both files because there is no more data in the threshold file
This program will do what you need. It reads all the values in data1.txt into the array #thresholds and pulls the contents of the file data2.txt into scalar $data. Then strings matching the regex pattern threshold\d+ are replaced with one of the elements of #threshold by subtracting one from the number at the end of the string and using it as an index into the array. so threshold1 is replaced by $threshold[0], threshold2 by $threshold[1] etc. It finally reopens the data file for output and writes the modified string into it
The program expects the paths to the two files as parameters on the command line, so it should be run as perl thresh_replace.pl data1.txt data2.txt
use strict;
use warnings;
use v5.10.1;
use autodie;
my ($thresholds_file, $data_file) = #ARGV;
my #thresholds = do {
open my $fh, '<', $thresholds_file;
local $/;
split ' ', <$fh>;
};
my $data = do {
open my $fh, '<', $data_file;
local $/;
<$fh>;
};
$data =~ s/threshold(\d+)/$thresholds[$1-1]/g;
{
open my $fh, '>', $data_file;
print $fh $data;
}
output
a=1 b=2 c=3
d=4 e=5 f=6
g = 10 h=7 i=8
lines
lines
j= 9 k=11
l = 20
lines
lines
m = 30
lines
lines
use strict;
use warnings;
use Tie::File; #This module can use for reading and writing on the same file
my $File1 = "File1.txt";
my $File2 = "File2.txt";
my #array;
tie #array, 'Tie::File', $File2 || die "Error: Couldn't tie the \"$File1\" file: $!";
my $len = join "\n", #array;
open(FILE, $File1) || die "Couldn't open the file $File2: $!\n";
#Threshold and line count matches
my $lineCount = '1';
while(<FILE>)
{
my $line = $_;
if($line!~/^$/) { chomp($line);
#Replace threshold with the first file values
$len=~s/threshold$lineCount/$line/i; }
$lineCount++;
}
#array = split/\n/, $len;
untie #array;
close(FILE);

Comparing files line by line using a simple pattern match

I have two files: in the first file each line has some labels associated with it; the second file contains the labels which fall under certain categories.
File1 - labelled lines:
I have never had an issue. L_102 ----- L_127
I travel overseas and offer a lot of services that are very useful to me L_105 ----- L_134 ----- L_148
Expense to have L_522
Great benefits L_148
prestige L_118
File2 - categories under which the labels fall:
Issues:113,114,115,116,127
Benefits:105,220,154,543,590
General:148,134,154
I have written a Perl script to fetch labels from the first file.
#!/usr/bin/perl
use strict;
use warnings;
my $file = shift || "INPUTFILE";
my $outputfile = shift || "OUTPUTFILE";
open my $fh, '<', $file or die "Can not open '$file': $!";
open( OUTFILE, ">", $outputfile) or die "Can not open '$outputfile': $!";
while(my $w = <$fh>) {
my #matches = $w =~ m/(L_[0-9][0-9][0-9])/g;
for(#matches){s/L_//g;
s/\s+/\t/g;
}
print OUTFILE "#matches\n";
}
The output from this first script is:
102 127
105 134 148
522
148
118
I have a second Perl script to fetch the levels from second file (which contains the categories):
#!/usr/bin/perl
use strict;
use warnings;
my $file = shift || "INPUTFILE";
my $outputfile = shift || "OUTPUTFILE";
my $patern = shift ||"Issues:"
open my $fh, '<', $file or die "Can not open '$file': $!";
open( OUTFILE, ">", $outputfile) or die "Can not open '$outputfile': $!";
while(my $var = <$fh>) {
if(my #matches =$var=~/(.*$patern.*)/)
{
for(#matches){s/$patern//g;s/\,/\t/g}
print OUTFILE "#matches\n";
}
}
The second output from the second script is:
113 114 115 116 127
Now I want to match the first output with the second output line by line.
The results I want are: if the any of the numbers in the second output matches with any of the lines in the first output then I want to print 1; or else if there is no match print -1 for that line.
The output from the above would be as below:
1
-1
-1
-1
-1
This combines your two scripts into one. It reads through the $inputfile file handle that is pointing at "INPUTFILE.txt"looking for matches based on either a regular expression ($regexp) or the existence of a search key in the %patterns hash.
Since the match is simple, the regular expression we use is built up using join, |, and the required search strings. In the alternative approach (which is commented out here) we use the hash keys themselves to check whether a search pattern exists.
I have changed the variables and file names in the open statements somewhat since the capitalized file names made them seem like old style file handles:
#!perl -l
my $inputfile = "INPUTFILE.txt";
my $outputfile = "OUTPUTFILE.txt";
my $matchfile = "MATCHFILE.txt";
open my $inputfh, '<', $inputfile or die "No file '$inputfile': $!";
open my $matchfh, '<', $matchfile or die "No file '$matchfile': $!\n";
open my $outfh, '>', $outputfile or die "No file '$outputfile': $!\n";
my %patterns;
while (<$matchfh>) {
$patterns{$_} = () for map { split /,/, $_ } /Issues:(.*)/;
}
my $regex = join "|", keys %patterns;
$regex = qr/$regex/; # create a regex from %patterns
print "Search patterns : ", join " ", keys %patterns;
print "Regex : $regex \n";
while (my $line = <$inputfh>) {
chomp $line;
# Print "1" for 3 digits matching search pattern; "-1" otherwise:
#print exists $patterns{$_} ? "1" : "-1" for $line =~ m/(\d\d\d)/g;
# Print "1" if a matching pattern is on a line; -1 otherwise:
if (grep /$regex/, $line) { #
print "1 - $line";
}
else {
print "-1 - $line";
}
}
The above script should work. You can remove - $line from the last print statements and add a file handle destination ($outfh) to direct the output to a file.
Since there are five lines in the inputfile, the output is:
Search patterns : 127 116 114 115 113
Regex : (?^:127|116|114|115|113)
1 - I have never had an issue. L_102 ----- L_127
-1 - I travel overseas ... very useful to me L_105 ----- L_134 ----- L_148
-1 - Expense to have L_522
-1 - Great benefits L_148
-1 - prestige L_118
NB the final if ... else blocks could be shortened using the "ternary operator"(<cond> ? 1 : 0) to:
print $line =~ /$regex/ ? '1' : '-1';
so that "1" will printed if $line =~ /$regex/ evaluates to "true" (or "1") ; and "-1" will be printed if it evaluates to "false" (or "0").
If you read from your two files and simply redirect the output with your shell, the short version of all this would be:
#!perl -l
my $inputfile = "INPUTFILE.txt";
my $matchfile = "MATCHFILE.txt";
open my $inputfh, '<', $inputfile or die "No '$inputfile': $!";
open my $matchfh, '<', $matchfile or die "No '$matchfile': $!\n";
my %patterns;
while (<$matchfh>) {
$patterns{$_} = () for map { split /,/, $_ } /Issues:(.*)/;
}
my $regex = join "|", keys %patterns;
$regex = qr/$regex/;
while (my $line = <$inputfh>) {
chomp $line;
print $line =~ $regex ? '1' : '-1';
}

Perl - Start reading from specific line, and only get first column of it line, until end

I have a text file that looks like the following:
Line 1
Line 2
Line 3
Line 4
Line 5
filename2.tif;Smpl/Pix & Bits/Smpl are missing.
There are 5 lines that are always the same, and on the 6th line is where I want to start reading data. Upon reading data, each line (starting from line 6) is delimited by semicolons. I need to just get the first entry of each line (starting on line 6).
For example:
Line 1
Line 2
Line 3
Line 4
Line 5
filename2.tif;Smpl/Pix & Bits/Smpl are missing.
filename4.tif;Smpl/Pix & Bits/Smpl are missing.
filename6.tif;Smpl/Pix & Bits/Smpl are missing.
filename8.tif;Smpl/Pix & Bits/Smpl are missing.
Output desired would be:
filename2.tif
filename4.tif
filename6.tif
filename8.tif
Is this possible, and if so, where do I begin?
This uses the Perl 'autosplit' (or 'awk') mode:
perl -n -F'/;/' -a -e 'next if $. <= 5; print "$F[0]\n";' < data.file
See 'perlrun' and 'perlvar'.
If you need to do this in a function which is given a file handle and a number of lines to skip, then you won't be using the Perl 'autosplit' mode.
sub skip_N_lines_read_column_1
{
my($fh, $N) = #_;
my $i = 0;
my #files = ();
while (my $line = <$fh>)
{
next if $i++ < $N;
my($file) = split /;/, $line;
push #files, $file;
}
return #files;
}
This initializes a loop, reads lines, skipping the first N of them, then splitting the line and capturing the first result only. That line with my($file) = split... is subtle; the parentheses mean that the split has a list context, so it generates a list of values (rather than a count of values) and assigns the first to the variable. If the parentheses were omitted, you would be providing a scalar context to a list operator, so you'd get the number of fields in the split output assigned to $file - not what you needed. The file name is appended to the end of the array, and the array is returned. Since the code did not open the file handle, it does not close it. An alternative interface would pass the file name (instead of an open file handle) into the function. You'd then open and close the file in the function, worrying about error handling.
And if you need the help with opening the file, etc, then:
use Carp;
sub open_skip_read
{
my($name) = #_;
open my $fh, '<', $name or croak "Failed to open file $name ($!)";
my #list = skip_N_lines_read_column_1($fh, 5);
close $fh or croak "Failed to close file $name ($!)";
return #list;
}
#!/usr/bin/env perl
#
# name_of_program - what the program does as brief one-liner
#
# Your Name <your_email#your_host.TLA>
# Date program written/released
#################################################################
use 5.10.0;
use utf8;
use strict;
use autodie;
use warnings FATAL => "all";
# ⚠ change to agree with your input: ↓
use open ":std" => IN => ":encoding(ISO-8859-1)",
OUT => ":utf8";
# ⚠ change for your output: ↑ — *maybe*, but leaving as UTF-8 is sometimes better
END {close STDOUT}
our $VERSION = 1.0;
$| = 1;
if (#ARGV == 0 && -t STDIN) {
warn "reading stdin from keyboard for want of file args or pipe";
}
while (<>) {
next if 1 .. 5;
my $initial_field = /^([^;]+)/ ? $1 : next;
# ╔═══════════════════════════╗
# ☞ your processing goes here ☜
# ╚═══════════════════════════╝
} continue {
close ARGV if eof;
}
__END__
Kinda ugly but, read out the dummy lines and then split on ; for the rest of them.
my $logfile = '/path/to/logfile.txt';
open(FILE, $logfile) || die "Couldn't open $logfile: $!\n";
for (my $i = 0 ; $i < 5 ; $i++) {
my $dummy = <FILE>;
}
while (<FILE>) {
my (#fields) = split /;/;
print $fields[0], "\n";
}
close(FILE);