Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-30-2008, 07:17 AM   #1
Registered: May 2008
Posts: 32

Rep: Reputation: 15
Need Perl Script to extract last octent of an Argument


I need Perl script to extract last octent of third Argument in command line.


./ linux 2.6.26

Now i need to extract last octent 26 in third argument (ie., 2.6.26).

can anyone help on this?
Old 09-30-2008, 07:45 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 5,388

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
This is one way to do it:
my $number = $ARGV[1];
$number =~ s/.*\.(\d+)$/\1/;
print "number: $number\n";
Another way:
my ($first, $second, $third) = split /\./,  $ARGV[1];
print "number: $third\n";

Last edited by keefaz; 09-30-2008 at 07:48 AM.
Old 09-30-2008, 08:13 AM   #3
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 59
Is this homework? What have you tried so far?


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
Perl command line argument noir911 Programming 8 01-15-2008 04:59 AM
awk/perl script for extract data mruknown1 Programming 3 09-11-2007 09:19 AM
awk/perl script for extract data mruknown1 Linux - Newbie 2 09-11-2007 04:42 AM
perl pass regex check as an argument lord-fu Programming 2 08-29-2007 02:55 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:00 AM.

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