使用grep在其他bash文件中查找文件名(Find file names in other bash files using grep)
如何在输入文本文件中循环显示bash文件名列表,并为每个文件名grep目录中的每个文件(以查看文件中是否包含文件名),并将所有文件名输出到文本中在任何文件中找到?
#!/bin/sh #This script will be used to output any unreferenced bash files #included in the WebAMS Project #Read file path of bash files and file name input SEARCH_DIR=$(awk -F "=" '/Bash Dir/ {print $2}' bash_input.txt) FILE_NAME=$(awk -F "=" '/Input File/ {print $2}' bash_input.txt) echo $SEARCH_DIR echo $FILE_NAME exec<$FILE_NAME while read line do echo "IN WHILE" if (-z "$(grep -lr $line $SEARCH_DIR)"); then echo "ENTERED" echo $filename fi doneHow do I loop through a list of bash file names from an input text file and grep each file in a directory for each file name (to see if the file name is contained in the file) and output to text all file names that weren't found in any files?
#!/bin/sh #This script will be used to output any unreferenced bash files #included in the WebAMS Project #Read file path of bash files and file name input SEARCH_DIR=$(awk -F "=" '/Bash Dir/ {print $2}' bash_input.txt) FILE_NAME=$(awk -F "=" '/Input File/ {print $2}' bash_input.txt) echo $SEARCH_DIR echo $FILE_NAME exec<$FILE_NAME while read line do echo "IN WHILE" if (-z "$(grep -lr $line $SEARCH_DIR)"); then echo "ENTERED" echo $filename fi done最满意答案
将其另存为search.sh ,根据您的环境更新SEARCH_DIR :
#!/bin/bash SEARCH_DIR=some/dir/here while read filename do if [ -z "$(grep -lr $filename $SEARCH_DIR)" ] then echo $filename fi done然后:
chmod +x search.sh ./search.sh files-i-could-not-find.txtSave this as search.sh, updating SEARCH_DIR as appropriate for your environment:
#!/bin/bash SEARCH_DIR=some/dir/here while read filename do if [ -z "$(grep -lr $filename $SEARCH_DIR)" ] then echo $filename fi doneThen:
chmod +x search.sh ./search.sh files-i-could-not-find.txt更多推荐
发布评论