简体   繁体   English

查找结果未附加到文本文件

[英]find result not append to text file

Below script find result not appending to the text. 下面的脚本查找结果未附加到文本中。

file_vlist.txt file content file names as below file_vlist.txt文件内容的文件名如下

    filename1
    filename2
    ....

my script name is video.sh int having below code 我的脚本名称是video.sh int,具有以下代码

#!/bin/bash
filename="file_vlist.txt"
while read -r line
do
name="$line"
echo "*******video******** - $name\n" >> output_video_new.txt
find . -type f -exec grep -l '$name' '{}' \; >>output_video_new.txt
echo "*******video******** - $name\n" >> output_video_new.txt
done < "$filename"

result is appending to text below incorrect format 结果追加到格式不正确的文本后面

*******video******** - file1\n
./video.sh
*******video******** - file1\n
*******video******** - file2\n
./video.sh
*******video******** - file2\n
*******video******** - file3\n
./video.sh

This worked for me: 这为我工作:

#!/bin/bash

filename="filelines"
while read -r line
do
    name="$line"
    echo "*******video******** - $name"      >> output_video_new.txt
    find . -type f -exec grep -l $name {} \; >> output_video_new.txt
    echo "*******video******** - $name"      >> output_video_new.txt
done < "$filename"
  • Removed the ' chars in the find command. 在find命令中删除了'chars。 A variable inside ` chars is not evaluated. chars中的变量不被评估。
  • Removed the \\n in the echo commands, echo add a carriage return automatically. 在echo命令中删除\\ n,echo自动添加回车符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM