-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv2arff.sh
More file actions
executable file
·64 lines (59 loc) · 1.16 KB
/
csv2arff.sh
File metadata and controls
executable file
·64 lines (59 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
set -x
#Program:
# Convert .csv to .arff for weka
#2018/06/13 Ghost release
#E-mail: 296776435@qq.com
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:~/bin
#echo $PATH
file=$1
filepath=${file%.csv}
filename=${filepath##*\/}
echo "@relation $filename" >$2
attributesRow=$(sed -n '1p' $1)
firstDataRow=$(sed -n '2p' $1)
i=0
while((${#attributesRow}>0))
do
tmp=${attributesRow%%,*}
attributes[$i]="'"${tmp// /_}"'"
##${string//substring/replacement}
##echo "@attribute $attributes[$i] $datatype" >$2
remain=${attributesRow#*,}
if [ "$attributesRow" != "$remain" ]
then
attributesRow=$remain
else
break
fi
i=`expr $i + 1`
done
##got all attr name--attributes
i=0
while((${#firstDataRow}>0))
do
data[$i]=${firstDataRow%%,*}
if [ ${data[$i]:0} -gt 0 ]
then
datatype[$i]="NUMBERIC"
else
datatype[$i]="STRING"
fi
remain=${firstDataRow#*,}
if [ "$firstDataRow" != "$remain" ]
then
firstDataRow=$remain
else
break
fi
i=`expr $i + 1`
done
##got all attr type--datatype
i=0
while (( ${#attributes[@]} > $i ))
do
echo "@attribute ${attributes[$i]} ${datatype[$i]}" >>$2
i=`expr $i + 1`
done
echo "@data">>$2
sed -n '2,$p' $1>>$2