我想在两个或多个文本文件上应用一些操作(交集和重聚),所以在我将所有行放在一起后,我必须在该文件上应用排序和 uniq。问题是我想要相同的输入和输出文件(-i 不起作用)。这是我的代码:
nr_param=$#
case $1 in
'-r')
if [ "$nr_param" = 3 ]
then
echo "reuniunea"
rm -f reuniune1.txt
cat $2 $3 >> reuniune1.txt
sort <reuniune1.txt | uniq >reuniune.txt
rm -f reuniune1.txt
else
echo "parametri incorecti"
fi;;
'-i')
if [ "$nr_param" = 3 ]
then
echo "intersectia"
rm -f intersectie.txt
grep -Fx -f $2 $3 > intersectie.txt
else
echo "parametri incorecti"
fi;;
Run Code Online (Sandbox Code Playgroud)
你能帮我做同样的事情而不使用额外的文件吗?如果 $2 是“intersectie.txt”,则 grep 也是如此。