I read each line of the input file (IN) and print the line read into the output file (OUT) if the line starts with one of the patterns, for example "ab", "cd", "ef", "gh", "ij" and etc. The print line is in the form "pattern: 100" or form "pattern: 100: 200". I need to replace "pattern" with "myPattern", i.e. Print the current line in FILE, but replace all the text before the first appearance of ":" with "myPattern". What is the best way to do this?
I currently have:
while ( <IN> )
{
print FILE if /^ab:|^bc:|^ef:|^gh:/;
}
I'm not sure if substr substr will help, because the "pattern" can be "ab" or "cd" or "ef" or "gh" etc.
Thank! Bi
source
share