回答編集履歴

1

追記

2020/11/03 20:16

投稿

KojiDoi
KojiDoi

スコア13692

test CHANGED
@@ -9,3 +9,93 @@
9
9
  awk -F " *[=,] *" '{delete n; printf "%s=%s", $1,$2; n[$2]=1; for(i=3;i<=NF;i++){n[$i]++; if(n[$i]<=1) printf ",%s",$i;} printf "\n"}' hoge.bak > hoge
10
10
 
11
11
  ```
12
+
13
+
14
+
15
+ # 追記
16
+
17
+
18
+
19
+ だいぶん話が違っていたことがわかってきたので、改めて。
20
+
21
+
22
+
23
+ hoge.txt
24
+
25
+
26
+
27
+ ```
28
+
29
+ # aaaaa = t11111,t22222,t33333,t44444,t55555
30
+
31
+ aaaaa = t11111,t22222,t33333,t44444,t55555
32
+
33
+ bbbbb = t11111,t22222,t33333,t44444,t55555
34
+
35
+ ccccc = t11111,t22222,t33333,t44444,t11111,t22222,t99999
36
+
37
+ ```
38
+
39
+
40
+
41
+ test.awk
42
+
43
+ ```
44
+
45
+ BEGIN{
46
+
47
+ FS = " *[=,] *";
48
+
49
+ }
50
+
51
+ /^#/{
52
+
53
+ sub(/^# */, "", $1);
54
+
55
+ printf "%s=\n", $1;
56
+
57
+ next;
58
+
59
+ }
60
+
61
+ {
62
+
63
+ delete n;
64
+
65
+ printf "%s=%s", $1, $2;
66
+
67
+ n[$2]=1;
68
+
69
+ for(i=3; i<=NF; i++){
70
+
71
+ n[$i]++;
72
+
73
+ if(n[$i]<=1) printf ",%s", $i;
74
+
75
+ }
76
+
77
+ printf "\n";
78
+
79
+ }
80
+
81
+ ```
82
+
83
+
84
+
85
+ 実行
86
+
87
+
88
+
89
+ ```
90
+
91
+ $ awk -f test.awk hoge.txt
92
+
93
+ aaaaa=
94
+
95
+ aaaaa=t11111,t22222,t33333,t44444,t55555
96
+
97
+ bbbbb=t11111,t22222,t33333,t44444,t55555
98
+
99
+ ccccc=t11111,t22222,t33333,t44444,t99999
100
+
101
+ ```