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_ExtractLines

( 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_ExtractLines.txt . )



#####################################################################
# SCRIPT: SS_ExtractLines
#
# This script extracts the specified lines from a file.
#
# The name of the file from which lines are to be extracted
# is assigned using FVA (Forward Variable Assignment) for
# variable file is of form
# "C:/abc/x.txt" or "./x.txt"
#
# 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" (Ell-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_ExtractLines.txt, in a directory that is in your $path.
# The script can then be called as
#
# script SS_ExtractLines.txt file("mypage.html") from("1") to("5")
#
#
#####################################################################

# Declare FVA variables.
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

# Collect the content of $file in $content
var str content # Content of one file at a time
repro $file > $content # If the user did not assign $file, $content will be empty.

# Note that this script uses -e option for lex command.
# This is done so that the line numbers will be correctly
# accounted for. You may wish to edit the script to remove
# the -e option, if that suits your purpose better.

# Strip off all lines after $to.
var str lexArg
set $lexArg = $to+"[" # This will make the argument to lex command of form "n[".
# That means lex will extract all lines after the first
# n lines.
lex -e $lexArg $content >null # We do not want to see the output, just change $content.
# If the user has passed a negative value for $to, the lex command will
# produce an error, and will not strip any lines.

# Strip off all lines before $from.
# We will use the same str variable $lexArg declared above.
set $lexArg = "]"+$from # This will make the argument to lex command of form "]n".
# That means lex will extract all line before the n'th line.
# If the user has passed a negative value for $from, the lex command will
# produce an error, and will not strip any lines.
lex -e $lexArg $content >null # As before, we do not want to see the output.
# If the user has passed a negative value for $from, the lex command will
# produce an error, and will not strip any lines

# We are done. Return the content.
echo $content

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.