- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- find comand - executing >1 statement
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2005 11:59 PM
05-24-2005 11:59 PM
I'm attempting to execute >1 statement in within the -exec option of the find command:
bash-2.03$ find . -depth -type f -name "*.xml" -exec grep -l "summaryid" |awk -F/ '{print("cp" $0 "/tmp/" $NF)}' {} \;
find: incomplete statement
awk: can't open {}
From the command line above, I'm attempting to list the instances of files containing the string "simmaryid" within the current directory, and copy those files to another directory if the "grep" command succeeds. However, I obtained the error message shown above.
I had to resort to writting it in a longer method, which eventually works:
#!/bin/sh
find . -type f -name ".xml" -print |while read i
do
if [! `grep -l summaryid`]; then
echo "PATTERN DNE"
else
cp $i /tmp
fi
done
I was wondering if anyone could show me the method of executing >1 statement within the -exec option of the find command? I'm trying to do it within 1 line.
Thanks in advance.
Danny
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2005 12:12 AM
05-25-2005 12:12 AM
Re: find comand - executing >1 statement
find . -depth -type f -name "*.xml" -exec grep -l "summaryid" {} \; |awk -F/ '{print("cp" $0 "/tmp/" $NF)}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2005 12:14 AM
05-25-2005 12:14 AM
Re: find comand - executing >1 statement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2005 12:24 AM
05-25-2005 12:24 AM
Re: find comand - executing >1 statement
Try using xargs instead:
$ find . -depth -type f -name "*.xml" | xargs grep -l "summaryid" |awk -F/ '{print("cp" $0 "/tmp/" $NF)}'
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2005 03:20 AM
05-25-2005 03:20 AM
Re: find comand - executing >1 statement
I was wondering if there's another way of doing the same thing shown below, still the one-liner of the -exec option; but without using awk ?
Greatly appreciate any ideas.
Danny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2005 04:38 AM
05-25-2005 04:38 AM
Re: find comand - executing >1 statement
Create useme.awk as:
{print"cp", $0, "/tmp/" $NF}
Script file:
rm ./useit
find . -depth -type f -name "*.xml" | xargs grep -l "summaryid" |awk -f useme.awk > useit
chmod +x useit
./useit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2005 11:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2005 11:50 AM
05-25-2005 11:50 AM
Re: find comand - executing >1 statement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2005 02:15 AM
05-26-2005 02:15 AM
Re: find comand - executing >1 statement
# find . -depth -type f -name "*.xml" -exec grep -il "summaryid" {} \; | xargs -i cp {} /tmp/{}