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
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

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 01-14-2008
mercuryshipzz mercuryshipzz is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 16
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
  #2 (permalink)  
Old 01-14-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Code:
awk -F":" '/Total pancakes produced/ {print $2}' bakers.txt
  #3 (permalink)  
Old 01-14-2008
mercuryshipzz mercuryshipzz is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 16
thanks shamrock,

but i want tat to be in perl....

inside the program....

while executing i want in the format:

perl programname.pl total number of pancakes filename.txt
  #4 (permalink)  
Old 01-14-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,513
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;
    }
}
  #5 (permalink)  
Old 01-14-2008
mercuryshipzz mercuryshipzz is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 16
thanks ghostdog...
Closed Thread

Bookmarks

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 06:02 AM.


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