On 06/15/2021, at 18:28, @lbutlr <[email protected] <mailto:[email protected]>>
wrote:
> I have a file that has a few hundred lines, 77 of which are a HTML/XML style
> date element
>
> <date>Tue, 15 Jun 2021 17:12:26 -0600</date>
>
> I have another files that has 77 date lines in the same format. Everything is
> different dates, obvs.
>
> I want to replace the first date in file 1 with the first date in file 2, and
> so on through the entire file.
Hey Lewis,
I think what I'd do is:
1) Scrape the file 1 for the replacement date lines.
2) Paste them into this script in place of the dummy $input items:
#!/usr/bin/env perl -sw
use v5.010;
my $input = '
<date>Tue, 01 May 2021 17:12:26 -0600</date>
<date>Tue, 02 May 2021 17:12:26 -0600</date>
<date>Tue, 03 May 2021 17:12:26 -0600</date>
';
$input =~ s!\A\s+|\s+$!!g;
my @array = split(/\n/, $input);
my $counter = 0;
while (<>) {
if (m!<date>.+?</date>!) {
s!<date>.+?</date>!$array[$counter]!;
$counter++;
print;
} else {
print;
}
}
3) Open the file where the replacements are to take place to be frontmost in
BBEdit.
4) Run the script.
It works well on my test file (only lightly tested).
If I had more time and was feeling adventurous I'd do basically the same thing,
except:
1) My user-input would be the source and destination file paths.
2) I'd read the source file date items directly into an array.
3) Then I'd open the destination file and do the processing in-place.
I haven't played with reading and writing files for a while, so that's more
than I want to tackle at the moment.
--
Take Care,
Chris
--
This is the BBEdit Talk public discussion group. If you have a feature request
or need technical support, please email "[email protected]" rather than
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/bbedit/EE1628F6-0087-49A4-92D7-CAAC7B4385F4%40gmail.com.