需求:需要大批量的移除文件夹中的某一类语言文件,希望能批量执行
文件german.txt部分内容如下:
"/Library/Application Support/Apple/BezelServices/AppleBluetoothHIDKeyboard.plugin/Contents/Resources/de.lproj"
couldn’t be removed,because you didn't authorize this operation."
/Library/Application Support/Apple/BezelServices/AppleBluetoothHIDMouse.plugin/Contents/Resources/de.lproj"
couldn’t be removed,because you didn't authorize this operation.
"/Library/Application Support/Apple/BezelServices/AppleBluetoothMultitouch.plugin/Contents/Resources/German.lproj" couldn’t be removed,because you didn't authorize this operation.
"/Library/Application Support/Apple/BezelServices/AppleHSBluetooth.plugin/Contents/Resources/de.lproj" couldn’t be removed,because you didn't authorize this operation.
"/Library/Application Support/Apple/BezelServices/AppleTopCaseHIDEventDriver.plugin/Contents/Resources/de.lproj" couldn’t be removed,because you didn't authorize this operation.
"/Library/Application Support/Apple/BezelServices/IOAppleBluetoothHIDDriver.plugin/Contents/Resources/de.lproj" couldn’t be removed,because you didn't authorize this operation.
"/Library/Application Support/Apple/BezelServices/IOBluetoothHIDDriverGeneric.plugin/Contents/Resources/de.lproj" couldn’t be removed,because you didn't authorize this operation.........
1)获取对应路径,过滤路径外的关键词句子
#!/bin/bash
cat $1 |grep Library> localiation_path.txt #$1 表示运行脚本时,后面跟的文本
awk 'BEGIN {FS="\""}{print $2}' localiation_path.txt > localiation_final.txt
2)循环读取和删除对应的内容
#!/bin/bash
num=0
cat $1|while read line #$1 表示运行脚本时,后面跟的文本
do
rm -rf "$line"
let num+=1
echo $num
done
"$line" #需要用引号包含,才能解决路径中包含空格时不能执行命令的问题
读取过程的坑 # 被处理的文本中最后一行内容一定要包含换行符,否则有可能读出来少一行。
附:文本german.txt来源的语言搜索命令
#!/bin/bash
sudo find /Library -name German.lproj > find_loc.txt
sudo find /Library -name de.lproj >> find_loc.txt
cat find_loc.txt |sort > find_final.txt
总结
以上是编程之家为你收集整理的shell提取文件行的内容并执行全部内容,希望文章能够帮你解决shell提取文件行的内容并执行所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
小编个人微信号 jb51ccc
喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!