LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   How can I extract the .rpm filename from long list of entries using bash shell script (http://www.linuxquestions.org/questions/linux-software-2/how-can-i-extract-the-rpm-filename-from-long-list-of-entries-using-bash-shell-script-4175416656/)

Glenn D. 07-14-2012 03:36 AM

How can I extract the .rpm filename from long list of entries using bash shell script
 
Hello
How can I extract the .rpm filename from a long list of entries using bash shell script.
The .rpm filename is at the end of each line, one .rpm filename per line.
An small sample of entries see[1]

Thanks Glenn

[1]
25178 Jul 05 12 ./opensuse/repositories/home:/thomas-worm-datev:/branches:/openSUSE:/12.1:/Update/standard/i586/php5-enchant-5.4.2-2.10.i586.rpm
34376 Jul 05 12 ./opensuse/repositories/home:/thomas-worm-datev:/branches:/openSUSE:/12.1:/Update/standard/i586/php5-enchant-debuginfo-5.4.2-2.10.i586.rpm
37953 Jul 05 12 ./opensuse/repositories/home:/thomas-worm-datev:/branches:/openSUSE:/12.1:/Update/standard/i586/php5-exif-5.4.2-2.10.i586.rpm
48762 Jul 05 12 ./opensuse/repositories/home:/thomas-worm-datev:/branches:/openSUSE:/12.1:/Update/standard/i586/php5-exif-debuginfo-5.4.2-2.10.i586.rpm
1163812 Jul 05 12 ./opensuse/repositories/home:/thomas-worm-datev:/branches:/openSUSE:/12.1:/Update/standard/i586/php5-fastcgi-5.4.2-2.10.i586.rpm
2253098 Jul 05 12 ./opensuse/repositories/home:/thomas-worm-datev:/branches:/openSUSE:/12.1:/Update/standard/i586/php5-fastcgi-debuginfo-5.4.2-2.10.i586.rpm
177128 Jul 05 12 ./opensuse/repositories/home:/thomas-worm-datev:/branches:/openSUSE:/12.1:/Update/standard/i586/php5-fileinfo-5.4.2-2.10.i586.rpm
113810 Jul 05 12 ./opensuse/repositories/home:/thomas-worm-datev:/branches:/openSUSE:/12.1:/Update/standard/i586/php5-fileinfo-debuginfo-5.4.2-2.10.i586.rpm
1190720 Jul 05 12 ./opensuse/repositories/home:/thomas-worm-datev:/branches:/openSUSE:/12.1:/Update/standard/i586/php5-fpm-5.4.2-2.10.i586.rpm
12416684 Feb 14 12 ./opensuse/update/12.1/x86_64/xulrunner-devel-10.0.1-2.19.1.x86_64.rpm
12377361 Feb 10 12 ./opensuse/update/12.1/x86_64/xulrunner-devel-10.0-2.17.3.x86_64.rpm
12387183 Feb 23 12 ./opensuse/update/12.1/x86_64/xulrunner-devel-10.0.2-2.21.1.x86_64.rpm
12380383 Mär 27 12 ./opensuse/update/12.1/x86_64/xulrunner-devel-11.0-2.23.1.x86_64.rpm
12517313 Apr 27 12 ./opensuse/update/12.1/x86_64/xulrunner-devel-12.0-2.26.1.x86_64.rpm
12618902 Jun 19 12 ./opensuse/update/12.1/x86_64/xulrunner-devel-13.0-2.29.2.x86_64.rpm
14987262 Nov 17 11 ./opensuse/update/12.1/x86_64/xulrunner-devel-8.0-2.3.1.x86_64.rpm
14969617 Jan 23 12 ./opensuse/update/12.1/x86_64/xulrunner-devel-9.0.1-2.15.1.x86_64.rpm
14882742 Dez 22 11 ./opensuse/update/12.1/x86_64/xulrunner-devel-9.0-2.6.1.x86_64.rpm
86423 Nov 24 11 ./opensuse/update/12.1/x86_64/yast2-snapper-2.21.16.1-2.3.1.x86_64.rpm
49923 Feb 15 12 ./opensuse/update/12.1/x86_64/zlib-1.2.5_git201105272030-20.3.1.x86_64.rpm
51021 Feb 15 12 ./opensuse/update/12.1/x86_64/zlib-32bit-1.2.5_git201105272030-20.3.1.x86_64.rpm
55781 Feb 15 12 ./opensuse/update/12.1/x86_64/zlib-devel-1.2.5_git201105272030-20.3.1.x86_64.rpm
6915 Feb 15 12 ./opensuse/update/12.1/x86_64/zlib-devel-32bit-1.2.5_git201105272030-20.3.1.x86_64.rpm
107492 Feb 15 12 ./opensuse/update/12.1/x86_64/zlib-devel-static-1.2.5_git201105272030-20.3.1.x86_64.rpm
2613937 Jun 25 12 ./opensuse/update/12.1/x86_64/zsh-4.3.12-6.4.1.x86_64.rpm
405800 Jun 25 12 ./opensuse/update/12.1/x86_64/zsh-htmldoc-4.3.12-6.4.1.x86_64.rpm
45784 Jun 14 12 ./opensuse/repositories/home:/AndreasSchwab:/12.1/12.1/x86_64/orc-0.4.16-2.1.9.x86_64.rpm
33395 Jun 14 12 ./opensuse/repositories/home:/AndreasSchwab:/12.1/12.1/x86_64/orc-debuginfo-0.4.16-2.1.9.x86_64.rpm
8615 Jun 14 12 ./opensuse/repositories/home:/AndreasSchwab:/12.1/12.1/x86_64/orc-debugsource-0.4.16-2.1.9.x86_64.rpm
49739 Jun 14 12 ./opensuse/repositories/home:/AndreasSchwab:/12.1/12.1/x86_64/orc-doc-0.4.16-2.1.9.x86_64.rpm
404717 Jun 16 12 ./opensuse/repositories/home:/AndreasSchwab:/12.1/12.1/x86_64/oxygen-gtk-1.1.4-2.4.4.x86_64.rpm
361134 Jun 15 12 ./opensuse/repositories/home:/AndreasSchwab:/12.1/12.1/x86_64/oxygen-gtk-32bit-1.1.4-2.4.4.x86_64.rpm
4739806 Jun 16 12 ./opensuse/repositories/home:/AndreasSchwab:/12.1/12.1/x86_64/oxygen-gtk-debuginfo-1.1.4-2.4.4.x86_64.rpm
4384492 Jun 15 12 ./opensuse/repositories/home:/AndreasSchwab:/12.1/12.1/x86_64/oxygen-gtk-debuginfo-32bit-1.1.4-2.4.4.x86_64.rpm
5548 Jun 15 12 ./opensuse/repositories/home:/AndreasSchwab:/12.1/12.1/x86_64/oxygen-gtk-debugsource-1.1.4-2.4.4.x86_64.rpm
54102 Jul 03 12 ./opensuse/repositories/home:/AndreasSchwab:/12.1/12.1/x86_64/p11-kit-module-gnome-keyring-3.2.1-2.6.2.x86_64.rpm
52369 Jul 02 12 ./opensuse/repositories/home:/AndreasSchwab:/12.1/12.1/x86_64/p11-kit-module-gnome-keyring-32bit-3.2.1-2.6.2.x86_64.rpm
75112 Jul 03 12 ./opensuse/repositories/home:/AndreasSchwab:/12.1/12.1/x86_64/p11-kit-module-gnome-keyring-debuginfo-3.2.1-2.6.2.x86_64.rpm
69578 Jul 02 12 ./opensuse/repositories/home:/AndreasSchwab:/12.1/12.1/x86_64/p11-kit-module-gnome-keyring-debuginfo-32bit-3.2.1-2.6.2.x86_64.rpm

unSpawn 07-14-2012 04:18 AM

Using
Code:

awk -F'/' '/\.rpm$/ {print $NF}'
to pipe through or adding a file name as last element returns all lines ending in ".rpm" and displays the last item of slash-separated strings, meaning here all package names.

Glenn D. 07-14-2012 05:42 AM

Thanks for the details this worked --Glenn
# cat t.txt
198341 Feb 26 12 ./linux/misc/mondorescue/opensuse/12.1/i386/mindi-2.1.1-1.opensuse12.1.i586.rpm
323850 Feb 26 12 ./linux/misc/mondorescue/opensuse/12.1/i386/mindi-2.1.1-1.opensuse12.1.src.rpm
203899 Jun 04 12 ./linux/misc/mondorescue/opensuse/12.1/i386/mindi-2.1.2-1.opensuse12.1.i586.rpm
332979 Jun 04 12 ./linux/misc/mondorescue/opensuse/12.1/i386/mindi-2.1.2-1.opensuse12.1.src.rpm
205445 Jul 08 12 ./linux/misc/mondorescue/opensuse/12.1/i386/mindi-2.1.3-1.opensuse12.1.i586.rpm
334907 Jul 08 12 ./linux/misc/mondorescue/opensuse/12.1/i386/mindi-2.1.3-1.opensuse12.1.src.rpm
243145 Feb 26 12 ./linux/misc/mondorescue/opensuse/12.1/i386/mindi-busybox-1.18.5-2.opensuse12.1.i586.rpm
3132736 Feb 26 12 ./linux/misc/mondorescue/opensuse/12.1/i386/mindi-busybox-1.18.5-2.opensuse12.1.src.rpm
1132975 Feb 26 12 ./linux/misc/mondorescue/opensuse/12.1/i386/mondo-3.0.1-1.opensuse12.1.i586.rpm
2532903 Feb 26 12 ./linux/misc/mondorescue/opensuse/12.1/i386/mondo-3.0.1-1.opensuse12.1.src.rpm
# cat t.txt | awk -F'/' '/\.rpm/ {print $NF}'
mindi-2.1.1-1.opensuse12.1.i586.rpm
mindi-2.1.1-1.opensuse12.1.src.rpm
mindi-2.1.2-1.opensuse12.1.i586.rpm
mindi-2.1.2-1.opensuse12.1.src.rpm
mindi-2.1.3-1.opensuse12.1.i586.rpm
mindi-2.1.3-1.opensuse12.1.src.rpm
mindi-busybox-1.18.5-2.opensuse12.1.i586.rpm
mindi-busybox-1.18.5-2.opensuse12.1.src.rpm
mondo-3.0.1-1.opensuse12.1.i586.rpm
mondo-3.0.1-1.opensuse12.1.src.rpm


All times are GMT -5. The time now is 03:16 AM.