如何简化shell命令



 cd \txt
filelist=`ls`
for file in $filelist
do
    >temp.txt
    echo $file
    cat $file | uniq >> temp.txt
    >$file
    cat temp.txt >> $file
done

如上面代码所示:功能需求是将该目录下所有文件进行cat uniq操作之后保存回该文件,我使用了temp.txt,不知道有没有可以直接写回文件的命令?请指导!

shell linux命令 Linux 命令行 unix

bossbug 9 years, 8 months ago

配合zsh使用

世界好可爱 answered 9 years, 8 months ago


 bash


 cd \txt
filelist=`ls`
for file in $filelist
do
    echo $file
    cat $file | uniq - $file
done

蕾米俺D嫁! answered 9 years, 8 months ago

建议加上sort命令
cat $file | uniq| sort -o $file

Dimmi. answered 9 years, 8 months ago

改用python吧

天下基友是一家 answered 9 years, 8 months ago

Your Answer