| ||||||||||||||
basic regexp problem Posted by maxell (maxell), 15 August 2005 Code:
it seem the regexp didn't open the file? the result always 0 , have read the manual but still confused the function of the just simple 1. read from string and compare with var $name, and if the define $name found on file it will return with word "test" sample list.txt Code:
as u can see there is 5 dupe, what i want is the script count the dupe(and make the announce puts "no of dupe : $dupe", and if possible delete the 4 field and leave 1 alone, pls help, i have try to search this at google,manual still confuse, Posted by maxell (maxell), 16 August 2005 play a bit at some sample script, and get this :Code:
what i got, yes it read but only first line of file , it didn't read until eof of file, and i have read eof at tcl man but still didn't know how to implement that so make the script read until eof, also pls help me how to make the script also read the dupe text found (perline) -- like "puts "found number of name dupe : $" Posted by admin (Graham Ellis), 16 August 2005 The open command only opens the file ready for reading ... it doesn't actually read anything at all.fgets reads a single line of data. That's why you're only getting a report about the first line. You need to run your fgets in a loop that keeps going while there's still data available if you want to process every line of the file. See examples in the Tcl Input/Output module listed under [url=http://www.wellho.net/resources/modules.html] Posted by maxell (maxell), 16 August 2005 hmm cann't found tcl/input outputCode:
btw how to count the found result and make it as var? and if possible delete the dupe and just leave 1, pls help, show the code Posted by admin (Graham Ellis), 16 August 2005 Sorry - try "file and directory handling" ... I was posting through my mobile phone and couldn't check the exact wording!Posted by maxell (maxell), 17 August 2005 how to regex this data ?[space]name[space] ? have try with /s[name]/s but didn't work Posted by admin (Graham Ellis), 17 August 2005 Try{\sname\s} Posted by maxell (maxell), 18 August 2005 {\sname\s}ok work,but why didn't work {\s$var\s} ? how to regex a [space]var[space] , sorry if i asked twice,i thought before that was same ,but it's diff,pls help Posted by admin (Graham Ellis), 18 August 2005 It didn't work with the variable name because the curly braces defer the interprettaion on the variable that starts with the $ character.You'll need something like "\\s$name\\s" Where the $ variable will be interpretted and the \ is protected by a second \ from the Tcl shell ... Posted by maxell (maxell), 19 August 2005 thanks for that, works good. 1 last quest, how to define the match result? sample:Code:
[regexp "\\s$name\\s" $line] --> the result should return as $result right? how to define custom var name ? Posted by admin (Graham Ellis), 19 August 2005 To capture the whole match string, put an extra variable name (without the $ since you're setting in) on the end of the regex command. To capture just an an interesting bit of the match string, put round brackets around the part(s) of the regular expression to which you want to capture the matches, and add extra variable names (in addition to the one that catches the whole match) on the end of the command. To capture / check whether there was a match at all, check the return value from regex - it will be true if there was a match and false if there wasn't. Example set gotit [regexp {([[:graph:]]+)@([[:graph:]])} $in x y z will match an email address (nonspaces@nonspaces) and capture: gotit as a flag as to whether or not the match worked. if it did: x is the email address as a whole y is the user name z is the domain name Posted by maxell (maxell), 19 August 2005 hmm, u seem missunderstood my question .pls reread again my code Posted by admin (Graham Ellis), 19 August 2005 I have read your code and think I still don't understand your question.Posted by Dimon (Dimon), 7 December 2005 Hi Maxell!If I understood your question correctly, you can construct your command line using $var in 'regexp' command like a string and run it later with 'eval' command: Code:
It must works. This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| |||||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |