I am trying to retrieve the output of zypper search
in a particular format.
When I run zypper search
on my repo with the following command: zypper search --details --repo my_repo_alias
, I get an output that looks like this:
| Mesa | package | 22.3.5-150500.75.2 | x86_64 | my_repo_alias
| Mesa | srcpackage | 22.3.5-150500.75.2 | noarch | my_repo_alias
| Mesa-dri | package | 22.3.5-150500.75.2 | x86_64 | my_repo_alias
| Mesa-drivers | srcpackage | 22.3.5-150500.75.2 | noarch | my_repo_alias
| Mesa-gallium | package | 22.3.5-150500.75.2 | x86_64 | my_repo_alias
| Mesa-libEGL1 | package | 22.3.5-150500.75.2 | x86_64 | my_repo_alias
| Mesa-libGL1 | package | 22.3.5-150500.75.2 | x86_64 | my_repo_alias
| Mesa-libglapi0 | package | 22.3.5-150500.75.2 | x86_64 | my_repo_alias
However, I need to get the above info in this format:
Mesa-22.3.5-150500.75.2.x86_64.rpm
Mesa-22.3.5-150500.75.2.noarch.rpm
Mesa-dri-22.3.5-150500.75.2.x86_64.rpm
Mesa-drivers-22.3.5-150500.75.2.noarch.rpm
Mesa-gallium-22.3.5-150500.75.2.x86_64.rpm
Mesa-libEGL1-22.3.5-150500.75.2.x86_64.rpm
Mesa-libGL1-22.3.5-150500.75.2.x86_64.rpm
Mesa-libglapi0-22.3.5-150500.75.2.x86_64.rpm
Currently, to do this I’m using this code:
while IFS= read -r line; do
package_name=$(echo "$line" | awk '{print $2}')
package_version=$(echo "$line" | awk '{print $6}')
package_arch=$(echo "$line" | awk '{print $8}')
concatenated_info="$package_name-$package_version.$package_arch.rpm"
done < <(zypper search --details --repo sles_base_os_repo)
I think this is not ideal as this is using the position of certain fields (name, version, arch) to retrieve the necessary info to make the concatenated string. While unlikely, the position of these fields might be subject to change which would break the code.
I have been looking the zypper
command to see if there is a way I can control how the above info is outputted but haven’t found anything yet. Is anyone aware of something that might be available with zypper
that would allow me to output the above info without needing to use the awk
command I have currently?