G'day ovedpo15,
"I'm trying to add the whole list of packages ... and then iterate over each such block and extract the repository name ... I'm struggling with the parsing part. Is it possible to get a suggestion on a how to parse the output of zypper info?"
Redirect the output of your zypper info command to a file; e.g.
$ /usr/bin/zypper info ... > info.out
Then this code
#!/usr/bin/env perl use strict; use warnings; use autodie; my $file = 'info.out'; my %repo_for; { open my $fh, '<', $file; local $/ = "\nInformation for package "; while (<$fh>) { next unless /\A([^:]+).*?Repository\s+:\s(\S+)/ms; $repo_for{$1} = $2; } } # For demo use Data::Dump; dd \%repo_for;
will output:
{ "fontconfig-devel" => "prod-sdk12-sp5-pool-x86_64-hpc", "libedit0" => "prod-sp5-pool-x86_64-hpc", "Mesa-libEGL1" => "prod-sp5-pool-x86_64-hpc", "python-rpm-macros" => "prod-sdk12-sp5-pool-x86_64-hpc", }
See $/ for details about how that works.
— Ken
In reply to Re: How to parse the zypper info output?
by kcott
in thread How to parse the zypper info output?
by ovedpo15
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |