Suppose I have two text files - active-users.txt and all-user-info.txt
active-users.txt contains only numeric userIDs.
all-users.txt contains userIDs, and additional info fields.
What I need to do is to create a third text file which will contain the complete line of information for every userID in active-users.txt...
I've tried the following, in a bash script and on the command line:
for i in $(< active-users.txt)
do
grep $i all-users.txt >> active-user-info.txt
done
The broken bit that's driving me bonkers is that the active-user-info.txt output file always contains all of the contents of all-user-info.txt - and I'd expect it to only contain lines including the userIDs in activeUsers.txt
What am I missing?
grep -f active-users.txt all-users.txt
should do what you want... (I can turn this into an answer if that's good enough for you!) – Stephen Kitt Oct 11 '16 at 16:09active-users.txt
do match all the lines inall-user-info.txt
. Note that there's no structure here, so1
inactive-users.txt
would match1
anywhere in lines ofall-user-info.txt
: it would match1
or10
as an identifier, but also1
in the extra information. – Stephen Kitt Oct 11 '16 at 16:39Are you saying that any portion of userID can match, unless I use the -w flag?
– D Mooney Oct 11 '16 at 16:47-Fwf
all told). – Stephen Kitt Oct 11 '16 at 17:04