PRODUCT






Home









Free Download








Installation Instructions





FAQ





FAQ








Ask A Question





LEARN SCRIPTING





Overview








Lesson 1








2


3


4


5








Exam





SAMPLE SCRIPTS





Computer








Internet








Administrators








Developers








Data








Miscellaneous





HELP / DOCUMENTATION





Commands








Automated Internet








Automated Editors








Sample Scripts








Precompiled Functions








System Features






  Help Page - SS_FindLinesRE

( Some help pages may not display correctly in html because those help pages may have sample code
in them, part of which may be mis-interpreted as html tags.

All help pages, including this help page, are available in biterScripting with the help command. )




Sample Script SS_FindLinesRE Purpose Lists lines in a given file that contain a specified Regular Expression. Source Code ##################################################################### # SCRIPT: SS_FindLinesRE # # This script finds lines in a file that contain a specified Regular Expression. # # The Regular Expression is assigned using FVA (Forward Variable Assignment) # for variable $str. The value is of the form "(0>9)x(#a>z)", etc. # # The name of the file from which lines are to be found # is assigned using FVA for variable $file. The value if of the form # "C:/abc/x.txt" or "./x.txt" etc. # # The start line is assigned using FVA for str variable $from. The # value is of the form "1", "2", etc. If no value supplied, "1" is assumed. # # The end line is assigned using FVA for int variable $to. The # value is of the form "1", "100", etc. If no value is supplied, "l" (last line) is assumed. # # Note that $from and $to are str variables. If you are passing int values, use the makestr() function # as follows. # from(makestr(int(1))) to(makestr(int(5))) # # This script can be stored and edited as necessary, in a text file # called SS_FindLinesRE.txt, in a directory that is in your $path. # The script can then be called as # # script SS_FindLinesRE.txt str("href(=:)") file("mypage.html") from("1") to("5") # # ##################################################################### # Declare FVA variables. var str str # The first str is variable type, the second, variable name. var str file var str from var str to # Set start and end lines to default values if not assigned. if ($from=="") set $from="1" endif if ($to=="") set $to="l" endif # Extract lines in the range from the file. # We will collect the content in the following variable. var str content script SS_ExtractLines.txt file($file) from($from) to($to) >$content # We will count the line numbers in $content. # Note that the first line in $content is actually the $from'th line in $file. # So, to report correct original line numbers, we will add ($from-1) to $num. var int num if ($str <> "") do # We will be using a search string of the form "^abc^" for the sen command # inside the following while loop. We will cosntruct that search string here, # for performance reasons, so that it is not created each time around the loop. var str senArg set $senArg = "^"+$str+"^" while ($content <> "") do # Increment line number. set $num = $num+1 # Get the next line into a variable $line. var str line lex -e "1" $content >$line # We used the -e option to get even empty lines. If we did not use the -e option, # our reporting of line numbers would be incorrect. # Is our $str present in $line ? # Note that we are using -c option, but you may wish to change it based on # your requirements. if { sen -c -r $senArg $line } > 0 do # We found the search string. List the line. Remember to do the # correct line number calculation as described above. echo "Line: " ($num+makeint(str($from))-1) "\t" $line done endif done done endif

© 2008-2013, biterScripting.com. All rights reserved.
biterScripting, biterScript, biterBrowser, biterMobile, biterScripting.com, FVA (Forward Variable Assignment) are trademarks of biterScripting.com. Is it biterScripting-compatible ? is a service mark of biterScripting.com. Explorer, Unix, Windows are trademarks, service marks or other forms of intellectual property of their respective owners.