shell提取文件行的内容并执行

需求:需要大批量的移除文件夹中的某一类语言文件,希望能批量执行

文件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










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值