cp using awked lines

173 Views Asked by At
var=$(pwd);diff -x .DS* -r aa bb | cut -f3,4 -d' '| sed 's/\://' | awk -v "var=$var" 'BEGIN{OFS="/"} {split($2,a,"-"); a[1]=toupper(a[1]) if ($1 ~/^bb/) {print var, $1, $2 " " var, "aa"} 
else {print var, $1, $2 " " var, "bb"}}' | cp -r $(cut -f1 -d" ") $(cut -f2 -d" ")

This compares two directories and returns source and target addresses for copying purposes. The intended result is that both folders end up with the same files and folders inside them.

The cp-cut part doesn't work. Doing the cp manually produces the right result. The cut operations output seems OK.

Leaving off the cp-cut clause, the script produces lines like this

/Users/tom/Desktop/aa/AWK/awk-parse-email-add-or.textClipping /Users/tom/Desktop/bb

So this is the raw material - source file and target directory - to copy the awk clipping to the folder bb.

Could some kind person suggest where I am going wrong ?

Tom

1

There are 1 best solutions below

2
On BEST ANSWER

You're using command substitution, $(cut -f1 -d" ") and $(cut -f2 -d" "), but these commands are not valid because cut requires input.

Try using xargs instead. Change your last pipe to:

| xargs -n 2 cp -r