bash - Extract lines in file1 starting with a specific word given in file2 -
i have 1 file "file1" contains lines like:
643 2 3 4 5 6433 2 3 4 5 64 2 3 4 5 1234 2 3 4 5 1240 2 3 4 5 12 2 3 4 5 and extract lines first word contained in file 2, like:
12 64 thus, final result should be:
12 2 3 4 5 64 2 3 4 5 in bash think have use loop examining each word in file 2, not know command extract line in file1 containing exact word.
for example, using:
sed -n '/^64/p' file1 i get:
643 2 3 4 5 6433 2 3 4 5 64 2 3 4 5
which not correct, because line: 64 2 3 4 5
do know bash method (sed, grep, awk, or python if prefer) it?
you can use:
awk 'nr==fnr{a[$1]; next} $1 in a' file2 file1 64 2 3 4 5 12 2 3 4 5
Comments
Post a Comment