I have the cut command I want that grabs the first word in each line of a file.
I then want to put each word from the cut command into a foreach.
I then want to do a grep command inside the body of the foreach to grep for that word in another file.
Something like this:
@array = (cut /tmp/10218.after -f1);
foreach $word (@lines) {
grep $word /tmp/10218.before;
}
Obviously the @array assignment doesn't work. How do I get around this?
I'm sure there are many ways I just don't know what they are or which is best or good enough.
Best Answer
In bash
The
-q
to grep tells it to be quiet, you can then interrogate$?
to see if there was a match0
or not1
.