Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching in file 2

Status
Not open for further replies.

GOSCO

Technical User
Sep 26, 2000
134
GB
Hi how do I search a file for lines that has 7 semi colons in it e.g.

;sadasdasdasd;dfdfsfdg;ddd;dddddd;sddsds;dsdsd;
would be a valid line.
 
Read your file into an array then
foreach $line (@array) {
if ($line =~/(;.*){7}/) {
print "$line";
}
}

The 'if...' statement is saying the line matches if it contains a <semicolon followed by zero or many characters> 7 times.
 
maybe something like this to make sure it has exactly 7 semicolons, and no more. Untested, but it looks good:
Code:
/^(?:[^;]*;[^;]*){7}$/

#expanded out:

/     #start regex
^     #anchor to beginning of string
(?:   #start grouping (memory free, not saved in $1)
[^;]* #zero or more non-semicolon characters
;     #a literal semicolon
[^;]* #zero or more non ; char
)     #end grouping
{7}   #match exactly seven of the previous group
$     #anchor to the end of the string
/x    #end regex (x-modifier for multi-line)
----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Thanks for that guys, i'll give it a go!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top