首页 > 系统服务 > 详细

Linux处理批量文件的脚本

时间:2018-12-30 11:35:40      阅读:175      评论:0      收藏:0      [点我收藏+]

前言

  最好的方法不一定是你最快能想到的。这里提供一种使用sed命令构造命令解决处理批量文件的技巧,供参考。

需求案例1

  将当前目录下所有的0_80_91.txt、0_80_92.txt、0_80_93.txt、。。。等几十个文件的文件名修改为0_81_91.txt、0_81_92.txt、0_81_93.txt。也就是将文件名中的80修改为81。

  实现命令为:ls *.txt |sed -nr ‘s/(0_)(80)(.*)/mv \1\2\3 \181\3/gp‘ | sh

#ls *.txt 
0_80_91.txt  0_80_92.txt  0_80_93.txt
#ls *.txt |sed -nr s/(0_)(80)(.*)/mv \1\2\3 \181\3/gp
mv 0_80_91.txt 0_81_91.txt
mv 0_80_92.txt 0_81_92.txt
mv 0_80_93.txt 0_81_93.txt
#ls *.txt |sed -nr s/(0_)(80)(.*)/mv \1\2\3 \181\3/gp | sh
#ls *.txt
0_81_91.txt  0_81_92.txt  0_81_93.txt

需求案例1

  将当前目录下的所有的0_80_91.Z、0_80_92.Z、0_80_93.Z文件通过命令cc_uncompress调用解压并输出到指定文件。调用格式为cc_uncompress -s 0_80_91.txt -d 1.txt。1.txt可以是任意文件名。

  实现命令为:ls *.Z | sed -nr ‘s/(.*)/cc_uncompress -s \1 -d \1.txt/gp‘

#ls *.Z | sed -nr s/(.*)/cc_uncompress -s \1 -d \1.txt/gp
cc_uncompress -s 0_80_91.Z -d 0_80_91.Z.txt
cc_uncompress -s 0_80_92.Z -d 0_80_92.Z.txt
cc_uncompress -s 0_80_93.Z -d 0_80_93.Z.txt
#ls *.Z | sed -nr s/(.*)/cc_uncompress -s \1 -d \1.txt/gp | sh

 

Linux处理批量文件的脚本

原文:https://www.cnblogs.com/linyfeng/p/10198832.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!