The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Strip one line from 2 blank lines in a file tipsy Shell Programming and Scripting 6 06-23-2008 08:14 AM
strip first 4 and last 2 lines from a file using perl meghana Shell Programming and Scripting 10 02-01-2008 09:01 PM
Line deletion help using perl -ne lijju.mathew UNIX for Dummies Questions & Answers 1 01-02-2008 02:54 PM
One line perl command rsg00usa Shell Programming and Scripting 2 12-14-2005 05:45 PM
Regex to pick up name from the following including carriage return at end of the line Shakey21 Shell Programming and Scripting 3 07-18-2002 08:27 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2008
ramky79 ramky79 is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 56
how do i strip this line using perl regex.

I have a variable dynamically generated
$batch = /dataload/R3P/interface/Bowne/reports/RDI00244.rpt

Now I'd like to strip '/dataload/R3P/interface/Bowne/reports/RDI' and '.rpt' from this variable

my output should be only 00244
how to do this using perl regex.I'm a newbie to perl and would like to know how to do this.

thanks and regards,
Ram.
  #2 (permalink)  
Old 03-18-2008
quine quine is offline
Registered User
  
 

Join Date: Mar 2008
Location: Bay Area California
Posts: 68
Hello...

There are a few ways to do this, but if what you want is ALWAYS the digits in the middle of the file name, then this is probably easiest...

First, at the top of your program, put "use File::Basename;" This is a standard module included with Perl... Basename gives you the filename at the end of a path... Suppose the whole path name is in $myfullpath

use File::Basename

$myFile = Basename($myfullpath); # $myFile now RDI00244.rpt

$myFile =~ /(\d)/; #The () around \d (digits) captures the match so...
$mydigits = $1 # $1 because it's the first parentheses set in the patern

or you could do....

$myFile =~ s/(\d)/$1/; # now a direct substitution of the digits into $myFile

Hope that helps
matthew rapaport (quine@sonic.net)
Sponsored Links
Closed Thread

Bookmarks

Tags
perl, perl regex, regex

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0