We continue to explore another interesting example of text processing. That is, extract the package name from the full .rpm package file name, in two ways: using AWK and using Bash.
We take the package file omarine-update-3.2-1.x86_64.rpm to illustrate, and will extract to get "omarine-update"
You compose a source file named pkgname.awk with the following content:
OLDFS = FS
FS = "-"
$0 = $0
printf "%s", $1
for (i = 2; i <= NF - 2; i++)
printf "%s", "-"$i
FS = OLDFS
Run the program:
echo omarine-update-3.2-1.x86_64.rpm | awk -f pkgname.awk
We can use Bash itself to output "omarine-update". You run these commands:
Share on Twitter
Share on Facebook
Can't see mail in Inbox? Check your Spam folder.