Skip to main content
deleted 11 characters in body
Source Link
terdon
  • 252.3k
  • 69
  • 480
  • 718

First of all, please don't use a shell script for this sort of task, it is slow and error prone. In any case, grep can do what you want already:

grep -f BlockspamCLIs.txt *_All_events.csv >> output6.txt

From man grep:

       -f FILE, --file=FILE
              Obtain patterns from FILE, one per line.   If  this  option  is
              used  multiple  times  or  is  combined  with the -e (--regexp)
              option, search for all patterns given.  The empty file contains
              zero patterns, and therefore matches nothing.

-f FILE, --file=FILE

Obtain patterns from FILE, one per line. If this option is used multiple times or is combined with the -e (--regexp) option, search for all patterns given. The empty file contains zero patterns, and therefore matches nothing.

Next, if you do use a shell loop to iterate over the contents of a file, never do it with for i in $(cat file). And, you must always quote your variables to avoid various problems. For example, your command won't work if any of the lines in BlockspamCLIs.txt contain whitespace.

That said, if your lines don't have spaces or shell globbing characters, the command you show would work. It would be better written like this:

while IFS= read -r i; do
    grep -e "$i" -- *_All_events.csv >> output6.txt
    printf '%s\n' "$i"
done < BlockspamCLIs.txt

First of all, please don't use a shell script for this sort of task, it is slow and error prone. In any case, grep can do what you want already:

grep -f BlockspamCLIs.txt *_All_events.csv >> output6.txt

From man grep:

       -f FILE, --file=FILE
              Obtain patterns from FILE, one per line.   If  this  option  is
              used  multiple  times  or  is  combined  with the -e (--regexp)
              option, search for all patterns given.  The empty file contains
              zero patterns, and therefore matches nothing.

Next, if you do use a shell loop to iterate over the contents of a file, never do it with for i in $(cat file). And, you must always quote your variables to avoid various problems. For example, your command won't work if any of the lines in BlockspamCLIs.txt contain whitespace.

That said, if your lines don't have spaces or shell globbing characters, the command you show would work. It would be better written like this:

while IFS= read -r i; do
    grep -e "$i" -- *_All_events.csv >> output6.txt
    printf '%s\n' "$i"
done < BlockspamCLIs.txt

First of all, please don't use a shell script for this sort of task, it is slow and error prone. In any case, grep can do what you want already:

grep -f BlockspamCLIs.txt *_All_events.csv >> output6.txt

From man grep:

-f FILE, --file=FILE

Obtain patterns from FILE, one per line. If this option is used multiple times or is combined with the -e (--regexp) option, search for all patterns given. The empty file contains zero patterns, and therefore matches nothing.

Next, if you do use a shell loop to iterate over the contents of a file, never do it with for i in $(cat file). And, you must always quote your variables to avoid various problems. For example, your command won't work if any of the lines in BlockspamCLIs.txt contain whitespace.

That said, if your lines don't have spaces or shell globbing characters, the command you show would work. It would be better written like this:

while IFS= read -r i; do
    grep -e "$i" -- *_All_events.csv >> output6.txt
    printf '%s\n' "$i"
done < BlockspamCLIs.txt
added 6 characters in body
Source Link
Stéphane Chazelas
  • 584.9k
  • 96
  • 1.1k
  • 1.7k

First of all, please don't use a shell script for this sort of task, it is slow and error prone. In any case, grep can do what you want already:

grep -f BlockspamCLIs.txt *_All_events.csv >> output6.txt

From man grep:

       -f FILE, --file=FILE
              Obtain patterns from FILE, one per line.   If  this  option  is
              used  multiple  times  or  is  combined  with the -e (--regexp)
              option, search for all patterns given.  The empty file contains
              zero patterns, and therefore matches nothing.

Next, if you do use a shell loop to iterate over the contents of a file, never do it with for i in $(cat file). And, you must always quote your variables to avoid various problems. For example, your command won't work if any of the lines in BlockspamCLIs.txt contain whitespace.

That said, if your lines don't have spaces or shell globbing characters, the command you show would work. It would be better written like this:

while IFS= read -r i; do
    grep -e "$i" -- *_All_events.csv >> output6.txt
    printf '%s\n' "$i"
done < BlockspamCLIs.txt

First of all, please don't use a shell script for this sort of task, it is slow and error prone. In any case, grep can do what you want already:

grep -f BlockspamCLIs.txt *_All_events.csv >> output6.txt

From man grep:

       -f FILE, --file=FILE
              Obtain patterns from FILE, one per line.   If  this  option  is
              used  multiple  times  or  is  combined  with the -e (--regexp)
              option, search for all patterns given.  The empty file contains
              zero patterns, and therefore matches nothing.

Next, if you do use a shell loop to iterate over the contents of a file, never do it with for i in $(cat file). And, you must always quote your variables to avoid various problems. For example, your command won't work if any of the lines in BlockspamCLIs.txt contain whitespace.

That said, if your lines don't have spaces or shell globbing characters, the command you show would work. It would be better written like this:

while IFS= read -r i; do
    grep "$i" *_All_events.csv >> output6.txt
    printf '%s\n' "$i"
done < BlockspamCLIs.txt

First of all, please don't use a shell script for this sort of task, it is slow and error prone. In any case, grep can do what you want already:

grep -f BlockspamCLIs.txt *_All_events.csv >> output6.txt

From man grep:

       -f FILE, --file=FILE
              Obtain patterns from FILE, one per line.   If  this  option  is
              used  multiple  times  or  is  combined  with the -e (--regexp)
              option, search for all patterns given.  The empty file contains
              zero patterns, and therefore matches nothing.

Next, if you do use a shell loop to iterate over the contents of a file, never do it with for i in $(cat file). And, you must always quote your variables to avoid various problems. For example, your command won't work if any of the lines in BlockspamCLIs.txt contain whitespace.

That said, if your lines don't have spaces or shell globbing characters, the command you show would work. It would be better written like this:

while IFS= read -r i; do
    grep -e "$i" -- *_All_events.csv >> output6.txt
    printf '%s\n' "$i"
done < BlockspamCLIs.txt
Source Link
terdon
  • 252.3k
  • 69
  • 480
  • 718

First of all, please don't use a shell script for this sort of task, it is slow and error prone. In any case, grep can do what you want already:

grep -f BlockspamCLIs.txt *_All_events.csv >> output6.txt

From man grep:

       -f FILE, --file=FILE
              Obtain patterns from FILE, one per line.   If  this  option  is
              used  multiple  times  or  is  combined  with the -e (--regexp)
              option, search for all patterns given.  The empty file contains
              zero patterns, and therefore matches nothing.

Next, if you do use a shell loop to iterate over the contents of a file, never do it with for i in $(cat file). And, you must always quote your variables to avoid various problems. For example, your command won't work if any of the lines in BlockspamCLIs.txt contain whitespace.

That said, if your lines don't have spaces or shell globbing characters, the command you show would work. It would be better written like this:

while IFS= read -r i; do
    grep "$i" *_All_events.csv >> output6.txt
    printf '%s\n' "$i"
done < BlockspamCLIs.txt