Cutting specific name from configuration file

Hi falks,

I have the following configuration file structure:

file1:N
file2:Y
file3:Y
file4:N
......

I need to cut from the configuration file only the file with the sign "Y" in the end and copy it to some directory.

What is the best way to do it?

Thanks in advance,
Nir

#!/bin/ksh

configFile='file.cfg'

while IFS=: read fileName yn
do
   [ "${yn}" = "Y" ] && cp "${fileName}" newDirectory
done < "${configFile}"

Hey vgersh99,

Thanks a lot!
It's a very elegant solution!

best regards,
Nir

You got a solution. Anyway my try as,

awk '/:Y$/ { split($0,a,":"); print "cp "a[1]" ." }' <filename> | sh

It will work too.

HTH.

Hey muthukumar,

Thanks a lot for your solution.
I've checked it and it works ,but under specific circumstances:
The file in the configuration file must contain a full path.
My configuration file looks as the following:

RiGHTv/Java/lib/dispatcher.war:Y
CoreAPP/Java/deploy/RiGHTvCore.war:Y
XBIPApplication/Java/deploy/XBIPApplication.war:N
RiGHTv/Java/lib/Ris.war:N
SUIFW/Java/deploy/SUIFW.war:N
AMS/Java/deploy/Ams.ear:N
....

The file does not contain its root directory. The root directory is entered during the running, as an input from the user.The root directory is a build area of jar,war,ear,tar and sql files, which belongs to a specific build version.
Therefore,the solution of vgersh99 is more suitable for me because i concatenate the root directory to the file name from the conf file.
I wrote the following function:

copy_files_from_build_area()
{
configFile='copybuild.conf'

while IFS=: read fileName yn
do
[ "${yn}" = "Y" ] && check_if_file_exist && cp "${BUILD_DIR}/${fileName}" ${PRODUCTS_DIR}
done < "${configFile}"
}

Anyway,thanks a lot!

Best regards,
Nir

Yes. It is correct. We can try more derived ways as like,

awk '/Y$/ { split($0,a,":"); print a[1] }' testfile | while read file
do
cp ${BUILD_DIR}/${file}" ${PRODUCTS_DIR}
done

keep posting.

Now it works perfect!
Beautiful solution !

Best regards,
Nir

or you could do it ALL in awk:

nawk -v root="${BUILD_DIR}" '/:Y$/ { split($0,a,":"); print "cp " root "/" a[1]" ." }' <filename> | sh

Hey vgersh99,

Thanks again.

Finally,i chose your first solution:
while IFS=: read fileName yn
do
[ "${yn}" = "Y" ] && cp "${BUILD_DIR}/${fileName}" ${PRODUCTS_DIR}
done < "${configFile}"

Nir