xtsubstr

Section: User Commands (1)
Updated: 2002-10-26
Index Return to Main Contents

 

NAME

xtsubstr - extract substring and store as a new field

 

SYNOPSIS

xtsubstr -f attribute -R range list [-A] [-i INPUT] [-o OUTPUT] [-z] [-t]

 

DESCRIPTION

This command extracts a substring from attribute(s) at -f from range -R, and have the option to store it as a new attribute or replaces the original attribute value in place. The following shows several ways of specifying the region by -R
  (1) -R 1_4     : extract from the first to fourth characters
  (2) -R MIN_5   : extract from the first to fifth characters
  (3) -R 5_MAX   : extract from the fifth to the last characters
  (4) -R 2       : extract the second character
  (5) -R 1,5_MAX : extract the first character and from the fifth to the last characters Character position specified out of range will be ignored.

 

PARAMETERS

-f attribute
attribute to extract the substring from. Only one attribute can be specified at a time.
-R range list
specify the start and the last position of the specified attribute to be extracted.
-A new attribute
create a new attribute. If -A is not specified, the new value will replace the attribute in place.

 

FILE OPTIONS

-i input filename
if a suffix of the filename is '.gz', the command acts as a filter,
 extracting the compressed file for processing. The command will read the file as standard input when "-i" is not specified.
-o output filename
if a suffix of the filename is '.gz', the command automatically returns the output data in zip archi ve. When "-o" is not specified, the result will sent to standard output.
-z zip archive
compress the standard output to zip archive. When the option "-o" is not given and "-z" is specified, the output will be compressed as zip archive.
-t plain text
treat the input and output data as plain text format.

 

USAGE

Input file - dat.xt:
<field no="1">
<name>CustomerID</name>
</field>
<field no="2">
<name>Date</name>
</field>
<field no="3">
<name>TotalQuantity</name>
</field>
<field no="4">
<name>TotalAmount</name>
</field>
<body><![CDATA[
A00001 20020211 1 400
A00004 20020214 1 365
A00004 20020415 5 4349
A00004 20020625 3 5268
A00004 20020810 2 1805
A00004 20021014 2 612
A00005 20020918 12 4554
A00005 20020923 1 491
A00006 20020606 3 1364
A00006 20020918 5 2195
]]></body>
  Example 1. Modify the date attribute and print the 4 digit year. e.g. xtsubstr -fdate:year -R 1_4 -i dat.xt -o rsl.xt Output file -rsl.xt
<body><![CDATA[
A00001 2002 1 400
A00004 2002 1 365
A00004 2002 5 4349
A00004 2002 3 5268
A00004 2002 2 1805
A00004 2002 2 612
A00005 2002 12 4554
A00005 2002 1 491
A00006 2002 3 1364
A00006 2002 5 2195
]]></body>

Example 2. Append a new column to the data with 4 digit year and 2-digit day as the new field. e.g. xtsubstr -f Date:year_day -R 1_4,7_8 -i dat.xt -o rsl.xt Output file -rsl.xt

<body><![CDATA[
A00001 20020211 1 400 200211
A00004 20020214 1 365 200214
A00004 20020415 5 4349 200215
A00004 20020625 3 5268 200225
A00004 20020810 2 1805 200210
A00004 20021014 2 612 200214
A00005 20020918 12 4554 200218
A00005 20020923 1 491 200223
A00006 20020606 3 1364 200206
A00006 20020918 5 2195 200218
]]></body>

Example 3. Append a new column to the data with 2 digit month and 2-digit day as the new field. e.g. xtsubstr -f Date:month_day -R 5_MAX -A -i dat.xt -o rsl.xt Output file -rsl.xt

<body><![CDATA[
A00001 20020211 1 400 0211
A00004 20020214 1 365 0214
A00004 20020415 5 4349 0415
A00004 20020625 3 5268 0625
A00004 20020810 2 1805 0810
A00004 20021014 2 612 1014
A00005 20020918 12 4554 0918
A00005 20020923 1 491 0923
A00006 20020606 3 1364 0606
A00006 20020918 5 2195 0918
]]></body>

 

DIAGNOSTICS

The string extraction operation can only be done on one attribute at a time.

 

SEE ALSO

xtsel(1), xtuniq(1) For complete documentation and tutorial of xtsubstr and other commands, please visit http://musashien.sourceforge.net

 

BUG REPORT

If you find a bug in xtsubstr, please send an electronic mail to musashi@adm.osaka-sandai.ac.jp. Before sending a bug report, please verify that you have the lastest version of MUSASHI. Read this manual carefully to ensure the error is not caused by a quirk in the language.

 

AUTHORS

Yukinobu Hamuro, Naoki Katoh, Katsutoshi Yada, Stephane Cheung


 

Index

NAME
SYNOPSIS
DESCRIPTION
PARAMETERS
FILE OPTIONS
USAGE
DIAGNOSTICS
SEE ALSO
BUG REPORT
AUTHORS

This document was created by man2html, using the manual pages.
Time: 22:43:56 GMT, June 24, 2003