输入 :
Process1 |5f|03/29/13 15:32:59
Process1 |6f|03/29/13 17:59:03
Pro cess1 |s7|03/29/13 17:59:05
Pro cess1 |1234|03/29/13 20:33:43
Pro cess1 |L|03/29/13 20:33:54
A Pro cess |45g|03/29/13 20:34:59
A Pro cess |f4|03/29/13 21:10:22
B Pro cess |Es|03/30/13 00:11:25
B Pro cess |23|03/30/13 00:47:20
B Pro cess |E23|03/30/13 01:03:07
预期输出:
Process1 |5f|03/29/13 15:32:59
|6f|03/29/13 17:59:03
Pro cess1|s7|03/29/13 17:59:05
|1234|03/29/13 20:33:43
|L|03/29/13 20:33:54
A Pro cess |45g|03/29/13 20:34:59
|f4|03/29/13 21:10:22
B Pro cess |Es|03/30/13 00:11:25
|23|03/30/13 00:47:20
|E23|03/30/13 01:03:07
逻辑:仅保留第一列的一个实例,并将其他实例替换为空白
我试过这个,但没有用(在循环中使用下面的代码):
sed -e 's/Process1/ /g' -e 's/ /Process1/1' Input
(将 Process1 替换为“-”,然后再次将“-”的第一个实例替换为 Process1。
正如“cnicutar”所给出的,我将 awk 修改为:
awk -F "|" '{a[$1]++; if (a[$1] > 1) $1=""; 打印;}'文件
abv 的输出:
Process1 |5f|03/29/13 15:32:59
6f 03/29/13 17:59:03
Pro cess1 |s7|03/29/13 17:59:05
1234 03/29/13 20:33:43
L 03/29/13 20:33:54
A Process |45g|03/29/13 20:34:59
f4 03/29/13 21:10:22
B Pro cess |Es|03/30/13 00:11:25
23 03/30/13 00:47:20
E23 03/30/13 01:03:07
期望的输出(插入 |)
Process1 |5f|03/29/13 15:32:59
|6f|03/29/13 17:59:03
Pro cess1 |s7|03/29/13 17:59:05
|1234|03/29/13 20:33:43
|L|03/29/13 20:33:54
A Process |45g|03/29/13 20:34:59
|f4|03/29/13 21:10:22
B Pro cess |Es|03/30/13 00:11:25
|23 | 03/30/13 00:47:20
|E23| 03/30/13 01:03:07