我有一个.sh文件,里面有很多重复的释义。现在我需要删除这些重复项,只保留一个
例如
**startkeyword**
today is good
how are you
apple
**endKeyword**
**startkeyword**
today is good
how are you
apple
**endKeyword**
**startkeyword**
do you like apple
I like apple
**endKeyword**
**startkeyword**
today is good
how are you
**endKeyword**
**startkeyword**
today is good
how are you
apple
**endKeyword**
结果应该是:
**startkeyword**
today is good
how are you
apple
**endKeyword**
**startkeyword**
do you like apple
I like apple
**endKeyword**
**startkeyword**
today is good
how are you
**endKeyword**
我如何在。sh文件中做?可以自由使用sed、awk或tr
如果你不介意去掉星号**
awk -v RS='[*][*]n[*][*]' '{gsub(/[*]|n$/,""); if(!visited[$0]++) print $0}' file
输出startkeyword
today is good
how are you
apple
endKeyword
startkeyword
do you like apple
I like apple
endKeyword
startkeyword
today is good
how are you
endKeyword