加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 16:33:48 所属栏目:安全 来源:网络整理
导读:需求:需要大批量的移除文件夹中的某一类语言文件,希望能批量执行 文件german.txt部分内容如下: "/Library/Application Support/Apple/BezelServices/AppleBluetoothHIDKeyboard.plugin/Contents/Resources/de.lproj" couldn’t be removed,because you di

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读