in reply to Read and Create File
Also, I used the variable $printed to print a newline before each section except the first one.
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; my $printed; while (<>) { chomp; if (/^&LOG[ ]TEXT:[ ] " # The opening quote. [^"]*\\ # Path up to the last backslash. ( [^\\"]+ ) # The final part of the path. " # The closing quote. $/x ) { print "\n" if $printed++; say "[$1]"; } elsif (m{^&LOG[ ]Naming_Technique:[ ] [^@]+\@ # Anything up to the @. \w+/ # Word characters followed by a slash. ([^/]+)/ # The part_no. ([^/]+) # the part_rev. $}x ) { say "db_part_no=$1"; say "db_part_rev=$2"; } }
Save as create-ini.pl, run as
perl create-ini.pl input-file > output-file.ini
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Read and Create File
by szpt9m (Novice) on Jun 28, 2021 at 08:22 UTC |