使用grep在其他bash文件中查找文件名(Find file names in other bash files using grep)

系统教程 行业动态 更新时间:2024-06-14 16:57:40
使用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 done

How 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.txt

Save 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 done

Then:

chmod +x search.sh ./search.sh files-i-could-not-find.txt

更多推荐

本文发布于:2023-04-13 12:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/fc6e6e6e639159a38c5bb79b63274e3c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件名   文件   bash   grep   files

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!