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






  Sample Script - SS_FindLinesStr

( Some of the sample scripts may not be reproduced correctly in html because those scripts, especially web-related scripts, have html tags such as < tr > in their code.

For an accurate, copy-and-paste'able text version of this script, see SS_FindLinesStr.txt . )



#####################################################################
# SCRIPT: SS_FindLinesStr
#
# This script finds lines in a file that contain a specified string,
# called the search string.
#
# The search string is assigned using FVA (Forward Variable Assignment)
# for variable $str. The value is of the form "abc", etc.
#
# The name of the file from which lines are to be found
# is assigned using FVA for variable $file. The value is 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_FindLinesStr.txt, in a directory that is in your $path.
# The script can then be called as
#
# script SS_FindLinesStr.txt str("abc") 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.
# 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.
# (If $from has an erroneous value, such as -1, the line number reporting will be
# skewed.)
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 $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-2014, 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.