pattern matching + perl question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting pattern matching + perl question
# 1  
Old 12-05-2003
pattern matching + perl question

i can only find the first occurance of a pattern how do i set it to loop untill all occurances have changed.

Code:
#! /usr/bin/perl

use POSIX;

open (DFH_FILE, "./dfh") or die "Can not read file ($!)";

foreach (<DFH_FILE>) {
        if ($_ !~ /^#|^$/) {
                chomp;
                ($dfhtype, $dfh) = split(/=/, $_);
                $dfhtype=lc("$dfhtype");
                $dfhhash{$dfhtype}=$dfh;
        }
print "ORIGNAL:$dfhtype=$dfhhash{$dfhtype}\n";
}
close DFH_FILE;

while (($client, $dfh) = each (%dfhhash)) {
        ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
        $dfh =~ /\`date \+(%.*?)\`/;
        $str = strftime( "$1",$sec, $min, $hour, $mday, $mon, $year, $wday);
        print "CHANGED:$client=$`$str$'\n\n";
        print "DATE:$1\tTIME:$str\n";
}

[qgatu003]/export/home/mxdooley/mbi_script$./test.pl
ORIGNAL:q155944="DFH  1         CW_OMS           q155`date +%Y%m%d%H%M%S` `date +%Y%m%d%H%M%S`    q155944o01"
CHANGED:q155944="DFH  1         CW_OMS           q15520031205172139 `date +%Y%m%d%H%M%S`    q155944o01"

other various DFHes:
ACCESSDBTXT="DFH,1,q100,CW_TMS,`date +%Y%m%d`,`date +%H%M%S`,`date +%Y%m%d%H%M%S`,q100204i,0,1"
Q155940="DFH|1|q155|CW_OMS|`date +%Y%m%d`|`date +%H%M%S`|`date +%Y%m%d%H%M%S`|q155940i|0|1"

Last edited by Optimus_P; 12-05-2003 at 07:23 PM..
# 2  
Old 12-05-2003
FIXED it:
added a do while loop and cleared it all up.

dont know why i didnt see it earlier.

Code:
while (($client, $dfh) = each (%dfhhash)) {
        ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
        do { 
        $dfh =~ /\`date \+(%.*?)\`/;
        $str = strftime( "$1",$sec, $min, $hour, $mday, $mon, $year, $wday);
        $dfh="$`$str$'";
        print "CHANGED:$client=$dfh\n";
        } while ($dfh =~ /\`date \+(%.*?)\`/); 
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Perl Pattern Matching Question

Hi all, I have a pattern matching problem in which i'm not sure how to attack. Here is my problem: I have a list of strings that appear in the following format: String: LE_(1234 ABC)^2^ABC^DEFG What i need to do is replace all the characters after the first ^ with blank. So the output... (2 Replies)
Discussion started by: WongSifu
2 Replies

2. Shell Programming and Scripting

pattern matching question

Hi guys I have the following case statement in my script: case $pn.$db in *?.fcp?(db)) set f ${pn} cp ;; *?.oxa?(oxa) ) set oxa $pn ;; esac Can somebody help me to understand how to interpret *?.fcp?(db)) or *?.oxa?(oxa) ? I cannot figure out how in this case pattern maching... (5 Replies)
Discussion started by: aoussenko
5 Replies

3. Shell Programming and Scripting

pattern matching question

Hi Guys I am trying to check if the pattern "# sign followed by one or several tabs till the end of the line" exists in my file. I am using the following query: $ cat myfile | nawk '{if(/^#\t*$/) print "T"}' Unfortunately it does not return the desired output since I know for sure that the line... (4 Replies)
Discussion started by: aoussenko
4 Replies

4. Shell Programming and Scripting

Pattern matching question

Hi Guys, I am trying to setup a check for the string using an "if" statement. The valid entry is only the one which contain Numbers and Capital Alpha-Numeric characters, for example: BA6F, BA6E, BB21 etc... I am using the following "if" constract to check the input, but it fails allowing Small... (3 Replies)
Discussion started by: aoussenko
3 Replies

5. Shell Programming and Scripting

pattern matching question

Hi guys, I have a file in the following format: 4222 323K 323L D222 494 8134 A023 A024 49 812A 9871 9872 492 A961 A962 A963 491 0B77 0B78 0B79 495 0B7A 0B7B 0B7C 4949 WER9 444L 999O I need to grep the line... (5 Replies)
Discussion started by: aoussenko
5 Replies

6. Shell Programming and Scripting

Pattern matching question

Hi, I am writing a simple log parsing system and have a question on pattern matching. It is simply grep -v -f patterns.re /var/log/all.log Now, I have the following in my logs Apr 16 07:33:17 ad-font-dc1 EvntSLog: AD-FONT-DC1/NTDS ISAM (700) - "NTDS (384) NTDSA: Online defragmentation... (5 Replies)
Discussion started by: wpfontenot
5 Replies

7. Shell Programming and Scripting

Pattern matching question

Hi guys, I have the following expression : typeset EXBYTEC_CHK=`egrep ^"+${PNUM}" /bb/data/firmexbytes.dta` can anybody please explain to me what ^"+${PNUM}" stands for in egrep statement? Thanks -A (3 Replies)
Discussion started by: aoussenko
3 Replies

8. Shell Programming and Scripting

Perl pattern matching!!

Hi experts, I have many occurances of the following headers in a file. I need to grep for the word changed/inserted in the header, calculate the difference between the two numbers and list the count incrementally. Headers in a file look like this: ------------------- ---------------------... (6 Replies)
Discussion started by: nmattam
6 Replies

9. Shell Programming and Scripting

Perl Pattern Matching

Hello experts, I have a file containing the following text(shortened here). File Begin ---------- < # Billboard.d3fc1302a677.imagePath=S:\\efcm_T4 < Billboard.d3fc1302a677.imagePath=S:\\efcm_T4 --- > # Billboard.d3fc1302a677.imagePath=S:\\efcm_Cassini >... (2 Replies)
Discussion started by: nmattam
2 Replies

10. Shell Programming and Scripting

perl pattern matching

hi i am trying to get digits inside brackes from file , whose structure is defined below CREATE TABLE TELM (SOC_NO CHAR (3) NOT NULL, TXN_AMOUNT NUMBER (17,3) SIGN_ON_TIME CHAR (8) TELLER_APP_LIMIT NUMBER (17,3) FIL01 ... (2 Replies)
Discussion started by: zedex
2 Replies
Login or Register to Ask a Question