Lexicon
Lexicon

Reputation: 2627

Use file column in a CSV as filename, find and output full path for file in bash

I have a CSV file that contains two columns, a date column and a filename column

12-12-2019,file1.txt
12-3-2019,file2.txt
....

From it, I would like to create a list that contains the first column followed by the fullpath of the file in the second column.

12-12-2019,/tmp/dir1/file1.txt
12-3-1019,/opt/tmp/blah/file2.txt

The find command that I am using is:

find / -iname file1.txt

I would like to create a script that does this automatically and outputs a CSV, similar to the first one, but has the full path instead of just the name.

Upvotes: 0

Views: 296

Answers (1)

NinjaGaiden
NinjaGaiden

Reputation: 3146

#!/usr/bin/env bash

while IFS=, read -r f1 f2
do
        echo -ne "$f1,"
        find . -name "$f2" -printf "%P\n"
done < csvfile

You may need to adjust your find command but this is the generaral idea

Upvotes: 1

Related Questions