I am new to perl scripting and need help regarding a given problem. I have many files with details of persons. I want to print the contents from each of the file after a particular line and before a particular line. Example: (one of the file contains following details:)
My name is XYZ.
Address: ***
ID:12414
Country:USA
End XYZ
Another file contains details like:
My name is ABC.
Address: ###
ID:124344
Country:Singapore
End ABC
I want to print the lines from the first file after My name is XYZ
and before End XYZ
into my new file. Similarly, I want to print the contents from the second file after My name is ABC
and before End ABC
, into my new file.
I wrote the logic as below, but I am not sure of the perl syntax to print after and below a particular line.
while(<file1>)
{
if () # if we read the phrase "My name" in file1 start printing after this +line
{
print #print the contents into file3(output file)
if() # if we read the phrase "End" in file1 stop printing the content into +file3
}
}
I hope my question is clear. Any help is appreciated.