views:

232

answers:

2

I cannot for the life of me get this. Example of fails, the last line of which adds in sed, which is the ultimate goal:

find -maxdepth 1 -name "*.sql" -exec "mysql -D ootp < {}" \;
find -maxdepth 1 -name "*.sql" -exec "mysql -D ootp << {}" \;
find . -maxdepth 1 -name \"*.sql\" -exec /usr/bin/mysql -D ootp << sed -e 's/ , );/1,1);/g' {}

What gives?

+1  A: 

I'd rewrite all of the above to one of these variants:

find -maxdepth 1 -name '*.sql' -exec sed -e 's/ , );/1,1);/g' '{}' +     \
    | mysql -D ootp

find -maxdepth 1 -name '*.sql' -print0 \;                                \
    | xargs -0 sed -e 's/ , );/1,1);/g'                                  \
    | mysql -D ootp

find -maxdepth 1 -name '*.sql' -exec cat '{}' \;                         \
    | sed -e 's/ , );/1,1);/g'                                           \
    | mysql -D ootp

find -maxdepth 1 -name '*.sql' -exec sed -e 's/ , );/1,1);/g' '{}' \;    \
    | mysql -D ootp

The first variant requires GNU findutils 4.2.12, SRV4-derived find, or some other POSIX-compatible find and should be the most efficient, but may not work in all find implementations (notably, I believe BSD find misses that feature).

ephemient
A: 

<< is the 'here document', but you're using it as it was a filename and/or a stream.

Sounds like you want

find . -maxdepth 1 -name '*.sql' -exec "sed -e 's/ , );/1,1);/g' '{}' | /usr/bin/mysql -D ootp" \;

if you're using -maxdepth 1 perhaps you could just do

for i in *.sql ; do 
  sed -e 's/ , );/1,1);/g' "$i" | /usr/bin/mysql -D ootp
done
nos