I coded a script in AWK to format the following lines (in a TXT file) to an ARFF
example.txt source:
Att_0 | Att_1 | Att_2 | ... | Att_n
1 | 2 | 3 | ... | 999
My script (to_arff), you can change FS value depending on the separator used in the TXT file:
#!/usr/bin/awk -f
# ./<script>.awk data.txt > data.arff
BEGIN {
FS = "|";
# WEKA separator
separator = ",";
}
# The first line
NR == 1 {
# WEKA headers
split(FILENAME, relation, ".");
# the relation's name is the source file's name
print "@RELATION "relation[1]"\n";
# attributes are "numeric" by default
# types available: numeric, <nominal> {n1, n2, ..., nN}, string and date [<date-format>]
for (i = 1; i <= NF; i++) {
print "@ATTRIBUTE "$i" NUMERIC";
}
print "\n@DATA";
}
NR > 1 {
s = "";
first = 1;
for (i = 1; i <= NF; i++) {
if (first)
first = 0;
else
s = s separator;
s = s $i;
}
print s;
}
Output:
@RELATION example
@ATTRIBUTE Att_0 NUMERIC
@ATTRIBUTE Att_1 NUMERIC
@ATTRIBUTE Att_2 NUMERIC
@ATTRIBUTE Att_n NUMERIC
@DATA
1,2,3,9999
arff
file (in which case sed or awk might help) or dealing with it directly in weka? – chl