I think TooTea's answer points the right way, not this, which I will still keep up for reference reasons.
Long story short: RPM file name convention is complicated, and as shown below, not unique. There are hence cases where you literally cannot know what the correct package name and versioning is. Still, you can try.
However, since this is complicated, this can't simply be done with sed
and regular expressions. Wrong tool for the job. Instead, use Redhat's / Fedora's own tooling. This Python script should give you what you want:
#!/usr/bin/env python3
from dnf.subject import Subject
from sys import stdin
from typing import Set
import hawkey
def filename_to_name_candidates(filename: str) -> Set[str]:
subj = Subject(filename)
return {
candidate.name
for candidate in subj.get_nevra_possibilities(forms=hawkey.FORM_NEVRA)
}
names = set()
for line in stdin:
try:
names = names | filename_to_name_candidates(line)
except:
pass
for name in sorted(names):
print(name)
Save that somewhere (say, as filename2packagename
), make it executable, (chmod 755 filename2packagename
). You can then just pipe in your file of filenames:
./filename2packagename < listofnames.txt
awk 'BEGIN{FS=OFS="-"} {NF-=2; print}' file