LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices



Reply
 
Search this Thread
Old 11-21-2012, 07:51 AM   #1
LittleMaster
Member
 
Registered: Jun 2012
Posts: 98
Blog Entries: 1

Rep: Reputation: Disabled
Required help in cut command


Hi

how can i get only the package name only using cut command .its should split package name alone not version no.whether its possible to do by cut command

httpd-2.0.48-1.2.rpm . With Ubuntu / Debian the package name will have ...


httpd

Last edited by LittleMaster; 11-21-2012 at 07:54 AM.
 
Old 11-21-2012, 07:55 AM   #2
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,356

Rep: Reputation: 135Reputation: 135
Try this

Quote:
echo "httpd-2.0.48-1.2.rpm" | cut -d - -f 1
 
Old 11-21-2012, 08:07 AM   #3
LittleMaster
Member
 
Registered: Jun 2012
Posts: 98
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
.It work for httpd & not for httpd-devel

echo "httpd-devel-2.0.48-1.2.rpm" | cut -d - -f 1

Last edited by LittleMaster; 11-21-2012 at 08:08 AM.
 
Old 11-21-2012, 08:32 AM   #4
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,356

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by LittleMaster View Post
.It work for httpd & not for httpd-devel

echo "httpd-devel-2.0.48-1.2.rpm" | cut -d - -f 1

for httpd devel:

Code:
echo "httpd-devel-2.0.48-1.2.rpm" | cut -d - -f 1,2
 
Old 11-21-2012, 08:50 AM   #5
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,356

Rep: Reputation: 135Reputation: 135
Try this perl oneliner and pass any packagename with at the end :


Code:
perl -w  -e 'for (@ARGV) { if (/(([a-z]+-)+)+.*/) { $pkg = $1;$pkg =~ s/-$// ;print "$pkg\n";}}' httpd--2.0.48-1.2.rpm httpd-devel-2.0.48-1.2.rpm
 
Old 11-21-2012, 01:57 PM   #6
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,566
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by LittleMaster View Post
...httpd-2.0.48-1.2.rpm . With Ubuntu / Debian the package name will have ...
Is that correct, rpm packages on Ubuntu?

Code:
rpm -qa | grep http*
should then work.
 
Old 11-21-2012, 09:54 PM   #7
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,356

Rep: Reputation: 135Reputation: 135
Yes Little master,habitual is correct. What will you do with rpms in Ubuntu/Debian ... Will you use rpm2deb or only for splitting package name .....
 
Old 11-21-2012, 10:59 PM   #8
LittleMaster
Member
 
Registered: Jun 2012
Posts: 98
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
These result
echo "httpd-devel-2.0.48-1.2.rpm" | cut -d - -f 1,2
httpd-devel
echo "httpd-devel-2.0.48-1.2.rpm" | cut -d - -f 1
httpd
echo "cyrus-sasl-devel x86_64 2.1.23-13.el6" | cut -d - -f 1,2,3

cyrus-sasl-devel

I want the single command which search package name alone

echo "httpd-devel-2.0.48-1.2.rpm" | cut -d - -f 1,2,3

result

httpd-devel-2.0.48

how can i overcome numerical alone
 
Old 11-21-2012, 11:43 PM   #9
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,356

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by LittleMaster View Post
These result
echo "httpd-devel-2.0.48-1.2.rpm" | cut -d - -f 1,2
httpd-devel
echo "httpd-devel-2.0.48-1.2.rpm" | cut -d - -f 1
httpd
echo "cyrus-sasl-devel x86_64 2.1.23-13.el6" | cut -d - -f 1,2,3

cyrus-sasl-devel

I want the single command which search package name alone

echo "httpd-devel-2.0.48-1.2.rpm" | cut -d - -f 1,2,3

result

httpd-devel-2.0.48

how can i overcome numerical alone
yes little master you can use the perl one liner to get the exact what you want, have you tried it ??

Code:
perl -w  -e 'for (@ARGV) { if (/(([a-z]+-)+)+.*/) { $pkg = $1;$pkg =~ s/-$// ;print "$pkg\n";}}' httpd-2.0.48-1.2.rpm httpd-devel-2.0.48-1.2.rpm cyrus-sasl-devel-x86_64 2.1.23-13.el6
Or do one thing keep all your package names in a textfile name : test.txt and run like this from your command line

Code:
perl -wan -e 'for (@F) { if (/(([a-z]+-)+)+.*/) { $pkg = $1;$pkg =~ s/-$// ;print "$pkg\n";}}' test.txt
where test.txt is in the directory where you will run this perl command.

test.txt contains:

Code:
httpd-2.0.48-1.2.rpm 
httpd-devel-2.0.48-1.2.rpm 
cyrus-sasl-devel-x86_64.2.1.23-13.el6
Try this and reply.

Last edited by divyashree; 11-21-2012 at 11:45 PM.
 
Old 11-23-2012, 02:13 AM   #10
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,310

Rep: Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039
You could use --queryformat
Code:
rpm -qa --queryformat "%{NAME}\n"|grep http
http://linux.die.net/man/8/rpm
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to cut required fields from a slight uneven output shivaa Linux - General 1 10-04-2012 02:48 AM
Command/Script required to send an email alert in case command will not respond rajaniyer123 Linux - General 1 05-19-2012 02:12 PM
help with cut command using find. Cut last 8 characters leaving the rest ncsuapex Programming 4 09-16-2009 09:55 PM
How to use command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 08:16 PM


All times are GMT -5. The time now is 09:41 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration