I have a text file named train_ids.txt
, and a csv file named dataset.csv
.
The text file contains ids by this way:
dish_1.png
dish_5.png
The input csv file has a lot of colums and rows, but the first col contains ids. The first col is as follows:
dish_1
dish_2
dish_3
dish_4
dish_5
I want to write a bash script to read the ids from the text file, and get the corresponding row which has these ids, and then put the whole row into an new csv file to be as output.
So the output csv file should be like this:
dish_1 | whatever_1
dish_5 | whatever_5
Notes:
- In the output csv file, I mean by whatever the entire row
- We have to remove .png from the ids text file to be able to search
- The whole text file includes ids only as mentioned, there's no different lines
- The ids text file is sorted but the csv file isn't sorted
- ids in the text file are in the csv file for sure, so we don't need to skip or report any thing.
I don't know how to do so, could you help me?
whatever
? The entire row o of the csv file? Do we need to remove the.png
from the "id"s? Can there be other extensions? Can there be multiple.
in a name (e.g.foo.png.bar
)? Will the files be sorted so that line N in one file corresponds to line N in the other? Should lines with no matching entry be skipped or reported?