First of all bash scripts are realy cool. Last days they helped me many times in different situations.
Today i had the following task which i solved with bash script in a few lines of code.
On the remote machine i needed to find files which contained "phrase1" and at the same time not contained "phrase2". I didn't find a regular expression which could solve it in one Grep command, therefore i created two Grep commands using the output of the first Grep as input for the second Grep expression.
Finally, i wrote the following bash script:
#!/bin/bash
for i in `grep -r -l "phrase1" *`; do
if [ -f "$i" ]; then
grep -L "phrase2" "$i" >> log.txt
fi;
done
Just six lines of code. And it works )
Dear friend, i hope this post was helpful to you as it was for me.
P.S. Many thanks to Alexey Kirillov who helped me with this bash script. )
Подписаться на:
Комментарии к сообщению (Atom)
Комментариев нет:
Отправить комментарий