- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting Annoyance. Getting the base name from a ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2008 12:00 AM
тАО08-26-2008 12:00 AM
This is the name of a Red Hat rpm.
zsh-4.2.0-3.EL.3.i386.rpm
The base Name is everything to the left of the rightmost dash.
zsh-4.2.0 - 3.EL.3.i386.rpm
Sometimes like the one above the base name is two part.
Sometimes the base name is three part.
zsh-html-4.2.0-3.EL.3.i386.rpm
zsh-html-4.2.0 - 3.EL.3.i386.rpm
If I have the full rpm name in a variable, I'm struggling for a reliable way to extract the base name, everything to the left of the right most dash.
TS="zsh-html-4.2.0-3.EL.3.i386.rpm"
echo $TS | awk -F "-" '{print $1 $2 $3 $4 $5 }'
I'm actually opening a sed book thinking this might be the tool of choice.
10 points for a reliable, testable solution.
It will save me a ton of work on a project.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Solved! Go to Solution.
- Tags:
- RPM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2008 12:48 AM
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2008 12:53 AM
тАО08-26-2008 12:53 AM
Re: Scripting Annoyance. Getting the base name from a file name.
$ awk -F- '{print substr($0,1,index($0,$NF)-2)}' x
Look for the star position of the last chunk when split by dashes. Extract up to that point minus 2 for the dash itsef and for being 1 based.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2008 01:00 AM
тАО08-26-2008 01:00 AM
Re: Scripting Annoyance. Getting the base name from a file name.
The first perl command, very acceptable for this one time job got me through this issue.
I'm going to use that command to create a data file that will determine the latest, greatest version of each rpm and make a copy of the just that rpm to a new directory.
The point of this endeavor is to allow me to clean up an rpm repository that has multiple versions of many rpms. There is a lot of data space being eliminated.
Consider this thread on hold. People will get something for additional suggestions, but the original problem is solved.
Thanks.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2008 01:01 AM
тАО08-26-2008 01:01 AM
Re: Scripting Annoyance. Getting the base name from a file name.
Why not just use the shell functions
$ x="zsh-html-4.2.0-3.EL.3.i386.rpm"
$ echo ${x%-*}
zsh-html-4.2.0
$ x="zsh-4.2.0-3.EL.3.i386.rpm"
$ echo ${x%-*}
zsh-4.2.0
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2008 01:41 AM
тАО08-26-2008 01:41 AM
Re: Scripting Annoyance. Getting the base name from a file name.
full process:
# cd to rpm directory.
ls -1 | sort -u > file
perl -lne 'print $1 if /(.*)-/' file | sort -u > rpm.base.list
DEST="updates.trimmed/"
while read -r fn
do
nrpmname=$(grep $fn file| tail -n 1)
echo "I am going to copy .... $nrpmname"
TARGET="${DEST}${nrpmname}"
cp -p $nrpmname $TARGET
done < rpm.base.list
Now I'm about to build a patch distribution DVD. Hope it works.
Wish me luck.
No such thing as zero points in an SEP thread unless I think you are fishing. You last post if included in the original would have saved me a few minutes and therefore needs to be part of this post for purposes of documentation.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2008 02:08 AM
тАО08-26-2008 02:08 AM
Re: Scripting Annoyance. Getting the base name from a file name.
zsh-4.2.0-3
*including* the -3
this is the 3rd patch from redhat to zsh version 4.2.0, so maybe perl code like
my ($base, $rest) = split m/\./ => $modname, 2;
is better fitted to your needs
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2008 04:18 AM
тАО08-26-2008 04:18 AM
Re: Scripting Annoyance. Getting the base name from a file name.
One of the results of the loop returned whitespace with the last -n 1.
I need to probably add some grep code to the thing to avoid getting whitesspace or \n results.
Still really hot process. Its gonna save us a lot of GB if I iron it out.
I'm googling for the right grep command.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2008 04:20 AM
тАО08-26-2008 04:20 AM
Re: Scripting Annoyance. Getting the base name from a file name.
Talking to myself online now. Not good.
grep -v '^$'
Trying that. Going to insert it into the while loop. Blank lines are bad.
Other suggestions welcome.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2008 04:24 AM
тАО08-26-2008 04:24 AM
Re: Scripting Annoyance. Getting the base name from a file name.
> One of the results of the loop returned whitespace with the last -n 1. I need to probably add some grep code to the thing to avoid getting whitesspace or \n results.
You can do:
...
nrpmname=$(grep $fn file| tail -n 1)
[ -z "${nrpmname}" ] && continue
...
...which skips the empty element.
Regards!
...JRF...