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_Datafile

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



#####################################################################
# SCRIPT: SS_Datafile
#
# This sample script shows how to tabulate or process data in a datafile.
#
# In this sample script, we are using a file that lists customer data
# in the following format.
#
# name;address;telephone;email;account_number
#
# Each row contains data for one customer. All columns for that customer are separated by semicolons.
# Columns have varying widths. Spaces and other special characters may be present in columns.
# Some columns may be empty. The following is an example of one such data file.
#
# John Doe;123 Main Street,San Francisco,CA 12345,USA;123-456-7890;JohnDoe@something.com;87K9LM9J7
# S. Kumar;123 1st Lane,Bangalore,KA 12345,India;98-1234-5678;skumar@otherthing.com;98KLON5
#
# The name of the datafile is passed to the script via argument datafile.
#
# This sample script parses the datafile, extracts each customer's data one by one, and
# prints it out in tabular format. You can edit this sample script to process the data
# according to your needs.
#
# This script can be stored and edited as necessary, in a text file
# called SS_Datafile.txt, in directory C:/Scripts. The script can then be called as
#
# script SS_Datafile.txt datafile("C:/data")
#
# assuming the datafile is at C:/data .
#
# biterScripting can be downloaded free from http://www.biterscripting.com
#
#####################################################################

# Declare Farguments.
var str datafile

# We will set the word separator to semicolon, since all columns are separated
# by semicolon. But we will save the original value of separated to be restored later.
var str saved_wsep
set $saved_wsep = $wsep
set $wsep = ";"

# Read the contents of the file into a string variable.
var str data
cat $datafile > $data

# Read rows one by one
while ($data <> "")
do
var str row
lex -e "1" $data > $row

# The data for this row is in $row. Extract all the columns.

var str name, address, telephone, email, account

set $name = { wex -p "1" $row }
set $address = { wex -e -p "2" $row }
set $telephone = { wex -e -p "3" $row }
set $email = { wex -e -p "4" $row }
set $account = { wex -e -p "5" $row }

# Note that we used the -e option above because we want to get emtpy columns too.

# Print this customer in tabulated form.
echo $name "\t" $address "\t" $telephone "\t" $email "\t" $account

done

# Restore the previous value of word separator.
set $wsep = $saved_wsep

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.