![]() |
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 |
| ksh pattern matching | ripat | Shell Programming and Scripting | 5 | 02-10-2008 04:44 PM |
| help need for pattern matching | HIMANI | UNIX for Dummies Questions & Answers | 10 | 01-22-2008 07:30 AM |
| pattern matching in an if-then | lumix | Shell Programming and Scripting | 4 | 12-14-2007 04:25 PM |
| pattern matching | malle | Shell Programming and Scripting | 3 | 01-31-2007 05:23 AM |
| Pattern matching sed | leemjesse | Shell Programming and Scripting | 3 | 03-23-2005 04:06 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
pattern matching
Hi,
I am newbee to perl. I wanna search a file and fetch a pattern starting with "Total pancakes produced:" and get the numeric value present after the colon. but, the filename and the phrase(Total pancakes produced must be given as input since the input varies everytime.For example: the file we are gonna search might contain: Total pancakes produced: 30 Total muffin produced: 50 Total donuts produced: 70 i want to get the number 30 from tat file. the filename mite be bakers.txt assuming that the file might have only one occurance of this particular phrase we give as input. i am able fetch for one string but not for a bunch of string Since the line contains only one numeric value always i wud do it by using \d. can anybody give suggestions for my problem? thanks, mercury |
|
||||
|
check perldoc -f open (open files)
check perldoc -q read ( reading files) check perldoc -f chomp check perldoc perlre for regexp Code:
open(FILE,"<file") or die "Cannot open";
while (<FILE>) {
chomp($_);
($f1,$f2) = split(/[:]/, $_);
if (/Total pancakes produced/) {
print $2;
}
}
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|