你的意思是这样的?
#!/bin/bash
for f in "$@"
do
cp "$f" /tmp/tmp.dat
uniq /tmp/tmp.dat > "$f"
done
Run Code Online (Sandbox Code Playgroud)
您可以在包含许多*.dat文件的目录中运行的位置.如果你将它放在一个名为的脚本中uniq_dat,并使其可执行,你可以运行它:
uniq_dat *.dat
Run Code Online (Sandbox Code Playgroud)
使用排序!
sort -u foo -o foo
# is short for
sort --unique foo -o foo
# if you want to avoid sorting
sort —merge —unique foo -o foo
Run Code Online (Sandbox Code Playgroud)