Bops
January 2, 2020, 12:22pm
1
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
RudiC
January 2, 2020, 1:54pm
2
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
madeingermany:
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.
Hi
If there are multiple files should be used ; nextfile
instead ; exit
2 Likes
RudiC
January 3, 2020, 1:25pm
5
Might work as well:
cp -v $(grep -lE "([^,]*,){4}V," tmo*) /test/V_files/