Copy files if column 5 in a file contains “V”

I have number of csv files (like tmo_2019*). In these files some files have 5th column value as V. I want to copy those files having 5th column value as V to specific directory /test/V_files/.

I tried to extract file names by below but not able to complete command for copy.

find -type f -iname "tmo*"  -exec awk -F',' '$5 == "V" {print FILENAME}'  {} \;

How to complete command to copy these files having 5th column value as V.

Thanks In advance

How far would this (untested) get you?

awk -F',' '$5 == "V" {print "cp " FILENAME " /test/V_files/"}' tmo* | sh
2 Likes

In awk better print "quotes" around the filenames because they become command arguments in sh where unquoted arguments are subject to substitutions.

{print "cp \"" FILENAME "\" /test/V_files/"; exit}

The exit ensures that the filename is printed only once.

2 Likes

Hi
If there are multiple files should be used ; nextfile instead ; exit

2 Likes

Might work as well:

cp -v $(grep -lE "([^,]*,){4}V," tmo*) /test/V_files/