[英]Problems using grep and sed in bash
I'm extracting domains, subdomains and ips from a text file using: 我使用以下命令从文本文件中提取域,子域和ips:
grep -oE '[[:alnum:]]+[.][[:alnum:]_.-]+' "extra-domains.txt" | sed 's/www.//' | sort -u > outputfile.txt
And I'm using this bash to run it quicker as: extract-domains.sh text-with-domains.txt
我正在使用此bash使其更快地运行为: extract-domains.sh text-with-domains.txt
#!/bin/bash
FILE="$1"
while read LINE; do
grep -oE '[[:alnum:]]+[.][[:alnum:]_.-]+' "$LINE" | sed 's/www.//' | sort -u > outputfile.txt
done < ${FILE}
but I keep getting multiple errors with "No such file or directory" when running the bash. 但是在运行bash时,我始终收到“没有此类文件或目录”的多个错误。
Can anyone give me a hand? 有人可以帮我吗? Thanks. 谢谢。
The way you wrote it, grep takes "$LINE" as a filename. 编写方式,grep使用“ $ LINE”作为文件名。 Is that what it is supposed to do ? 那是应该做的吗?
edit : There is no point in making a while loop and reading your file line by line. 编辑:进行while循环并逐行读取文件没有意义。 It will be much slower. 它将慢很多。 You should probably write you script like this: 您可能应该这样编写脚本:
#!/bin/bash
grep -oE '[[:alnum:]]+[.][[:alnum:]_.-]+' "$1" |
sed 's/www.//' |
sort -u
and call it : 并称之为:
extract-domains.sh "extra-domains.txt" > outputfile.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.