Copy files based on content

Need to find all files in specific subdirectories ending in .xml. They'll either be in .../etc/apps/<dirname>/local/data/ui/views/*.xml or .../etc/apps/<dirname>/default/data/ui/views/*.xml. If the file in /etc/apps/<dirname>/default/data/ui/views/*.xml doesn't have the string version="1.1" in the first line, copy the file to the local directory as the same file name, add that string to the first line and quit.

I'm stuck on copying the file from its default dir to its local dir. I've got:

src=.../etc/apps/*/default/data/ui/views/*.xml
dest=.../etc/apps/*/local/data/ui/views/
pat='version='
for file in $src
do
    if [[ "$(sed -n '1{/version=/p};q' "$file")" ]]; then
        awk 'NR==1 {print; exit}' "$file"
        echo "No change necessary to $file"
    else
        echo "Copying $file to local ../local/data/ui/views/$file and running sed '1 s/>/ version="1.1">/'"
    fi
done

Which won't work because it's going to use the whole path for $file like I told it to. I get the feeling I'm overthinking this. But I'm not sure where to go from here.



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)