how to get the pos() of 2 str matches in one loop in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to get the pos() of 2 str matches in one loop in perl
# 1  
Old 07-25-2006
how to get the pos() of 2 str matches in one loop in perl

Hello all
i have this simple loop that gets me every time the match of "<#" in my string
something like that :

my $str ="gggg<#nnnnn#>kkkk<#ssss#>llllll";
while($str =~m/<#/g){
print pos($str);
}

but now i like to get another pos in the same loop iteration , i will like to get the match of "#>"
can it be done in perl ?
# 2  
Old 07-26-2006
What about

Code:
my $str ="gggg<#nnnnn#>kkkk<#ssss#>llllll";
 while($str =~m/(<#|#>)/g){
 print pos($str);
 }

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Displaying the first field if the second field matches the pattern using Perl

Hi, I am trying with the below Perl command to print the first field when the second field matches the given pattern: perl -lane 'open F, "< myfile"; for $i (<F>) {chomp $i; if ($F =~ /patt$/) {my $f = (split(" ", $i)); print "$f";}} close F' dummy_file I know I can achieve the same with the... (7 Replies)
Discussion started by: royalibrahim
7 Replies

2. Shell Programming and Scripting

Check Character matching from pos 7-15 to pos 211-219 if True then replace 211-219 with spaces

Script for if characters from positions 7-15 are matching with characters from position 211-219 then replace all char from 211-219 with 9 space. Total length of record is 420. Here is the specification of the data in file. Position Field Data Type... (5 Replies)
Discussion started by: lancesunny
5 Replies

3. Shell Programming and Scripting

Perl: Counting matches

Hi, A perl newbie here so pretty sure it's something simple. Trying to figure out how to count matches with perl pattern matching. The following script opens a text data file and finds lines containing "PORT:" and I'd like to count how many of these are found. Any ideas? open(LOG,"<... (3 Replies)
Discussion started by: hdefjunkie
3 Replies

4. UNIX for Dummies Questions & Answers

Req 1-liner for Awk, et al to find str position

Hi, I'm trying to find the position of a series of numbers within a large text file. The numbers are separated by spaces. This works fine: type Huge_File.txt | gawk "{print index($0,"255")}" But this does not: type Huge_File.txt | gawk "{print index($0,"188 028 239 160 016 190 137... (4 Replies)
Discussion started by: Lemming42
4 Replies

5. Shell Programming and Scripting

Perl - pass shell-vars into perl for input loop

I need to process a file line-by-line using some value from a shell variable Something like:perl -p -e 's/$shell_srch/$shell_replace/g' input.txt I can't make the '-s' work in the '-p' or '-n' input loop (or couldn't find a syntaxis.) I have searched and found... (4 Replies)
Discussion started by: alex_5161
4 Replies

6. Shell Programming and Scripting

Printing between 2 matches with Perl

Can we please modify this perl one-liner to print lines between pattern1 and pattern2 in a file? Currently it prints lines till pattern2. (4 Replies)
Discussion started by: anand_bh
4 Replies

7. Shell Programming and Scripting

Perl line count if it matches a pattern

#!/usr/bin/perl use Shell; open THEFILE, "C:\galileo_integration.txt" || die "Couldnt open the file!"; @wholeThing = <THEFILE>; close THEFILE; foreach $line (@wholeThing){ if ($line =~ m/\\0$/){ @nextThing = $line; if ($line =~ s/\\0/\\LATEST/g){ @otherThing =... (2 Replies)
Discussion started by: nmattam
2 Replies

8. UNIX for Dummies Questions & Answers

reg str concat

hi friends. i want to create new file name depends upon user input value.......the format is "txt_VVVV.txt". is it possible? #bin/ksh typeset -i10 i = $1 case $i in *) fil = "txt_000"$i".txt" ;; *) fil = "txt_00" $i... (4 Replies)
Discussion started by: ilayans
4 Replies

9. Shell Programming and Scripting

Matches and mismatches in perl

When we give an input sequence , the program should match with the pattern and give the matches and mismatches in the output. i will give you 2 small examples. if you cant get it pls let me know. i will try to give a clear idea. example 1: $a=APPLE; # let it be a pattern... (0 Replies)
Discussion started by: srisha
0 Replies

10. Shell Programming and Scripting

how to search for a str and replace it..

in my file, i like to search for a string and if there is a match then i want to replace it with someother string(like in windows wordpad). i only know how to search for a pattern.... but i dont know how to replace it.. and 1). i think it is there in unix grep or some other commends... if... (6 Replies)
Discussion started by: sekar sundaram
6 Replies
Login or Register to Ask a Question