Reputation: 2055
Then i use this script
for line in "`cat fromDirs.txt`";
do
find "$line" -type f \( -name '*good*' -o -exec grep -F "(NODES_'TASK')" {} \; \) -exec cp {} /tmp/ \;;
done
I get in folder /tmp only file names from where they are copied, but i need this filenames contains full paths from where they comes, im bored to trying fight with sed, please help
So i need just take each {} value and replace slash (/) with minus sign (-)
I trying many of variant but nothing good, this code do not work too
for line in "`cat fromDirs.txt`";
do
find "$line" -type f \( -name '*good*' -o -exec grep -F "(NODES_'TASK')" {} \; \) -exec cp {} /tmp/$(sed "s/\//-/g" <<< {}) \;;
done
file fromDirs.txt contains
/home/orders/
/etc/bin/school/
there are no output, just nothing haping, maybe beacause i use sh? i havent bash at all on system
I think the problem is in sed as it read placeholder {} as file instead of string, so if {} = /home/orders/good.php then sed open this file and change all slashes to minus sign, but i need to changeslashes only in filename so /home/orders/good.php -> -home-orders-good.php
and then cp to /tmp/-home-orders-good.php
Upvotes: 0
Views: 143
Reputation: 41460
I guess you get problem since you double quote the output of the file.
Try change from:
for line in "`cat fromDirs.txt`";
to:
for line in `cat fromDirs.txt`;
or better (remove old and outdated back tics):
for line in $(cat fromDirs.txt);
best (use while to read the file):
#!/bin/bash
while read line
do
find "$line" -type f \( -name '*good*' -o -exec grep -F "(NODES_'TASK')" {} \; \) -exec cp {} /tmp/$(sed "s/\//-/g" <<< {}) \;;
done < fromDirs.txt
Upvotes: 1