This command is used to return only distinct (unique) values from the defined attribute. It is commonly used to create key values or master file.
Summary of options and usage: xtuniq
Goal: Create a dataset with unique dates on each record.
Step 1: Editing your script
Startup FD. Repulciate the script "xtcut.sh" used in the previous lesson by selecting xtcut.sh and press "c+CTRL", you will then be prompted for a new name, name the new script as "xtuniq.sh"
copy the file xtcut.sh as a new name on the current directory
new name : xtuniq.sh
cp /home/public/lesson/basic/xtcut.sh /home/public/lesson/basic/xtuniq.shMethodology: Select "date" by xtcut, the result is sent as an input to the next command xtuniq by pipeline. The command combines same key values into one unique record. The output will pipe to xtheader, define a new title and comment as need, update the -o parameter and write the result to the file "xtuniq.xt".
Step 2: Defining Attributes and Options
Specify the parameters as follows:
Key - -k Date
Note: DATE will be the key attribute where duplicates will be removed.Your script will look like:
#/bin/bash
#===============================================================
# MUSASHI bash script
#===============================================================
#---- title
title="Tutorial"
#---- comment
comment="xtuniq"
#---- variables
inPath="/home/public/tutorial"
#---------------------------------------------------------------
# command
#---------------------------------------------------------------
xtcut -f Date -i $inPath/dat.xt |
xtuniq -k Date |
xtheader -l "$title" -c "$comment" -o xtuniq.xt #===============================================================Step 3: Running the Script
When you are done, save and execute the script. The result should look as follows:
<?xml version="1.0" encoding="euc-jp"?>
<xmltbl version="1.00">
<header>
<title>
Tutorial
</title>
<comment>
xtagg
</comment>
<field no="1">
<name>Date</name>
</field>
</header>
<body><![CDATA[
20020101
20020102
20020103
20020104
20020105
20020106
20020107
20020108
20020109
20020110
20020111
Let's apply xtuniq on the following reports. Check your results with the scripts and output files given below.
Report Description |
Script name | Output file (xt) | Output file (html) |
Create a master file of all brand codes | xtuniq1.sh | xtuniq1.xt | xtuniq1.html |
Create a master file of all manufacturer codes | xtuniq2.sh | xtuni2.xt | xtuniq2.html |