Find`s placeholder {} sed from variable1 and put into variable2
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
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
链接地址: http://www.djcxy.com/p/97122.html
上一篇: 终止由bash脚本执行的SSH会话