![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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) |
![]() |
| Bookmarks |
| Tags |
| perl, perl regex, regex |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|