I have two files:
aaaa 11 0.4 12 0.2
aaab 40 0.1 99 0.2 69 0.3
aaac 222 0.5 21 0.3
aaad 2 0.1
aaae 33 0.3
....
and
aaaa
aaac
aaae
....
I need to compare the first column of first file with second file and if a element is present in second file, write each line of the first file to a separate file. I have a script that does that in python but its extremely inefficient. Is it possible to do it from a terminal?
EDIT:
python script: LABEL_FILE would be the first example and other 'file' - list is present_images-list of files in a folder.
f = open(LABEL_FILE, 'r')
present_images = iter(os.listdir(os.path.join(IMAGES_PATH, dataset)))
templab = f.readlines()
num_info = len(templab)
image_ids = []
labels = []
labels_ind = []
for line in templab:
if len(line[:-1].split(' ')) != 1:
if (line[:-1].split(' ')[0] in present_images):
image_ids.append(os.path.join(IMAGES_PATH, dataset, line[:-1].split(' ')[0]))
line = line[:-1].split(' ')[1:]
labels_ind.append([int(i) for i in line[::2]])
labels.append([float(j) for j in line[1::2]])