- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- grep ^"string"
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
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
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-11-2010 10:42 PM
тАО05-11-2010 10:42 PM
grep ^"string"
I am looking to grep for file starting with a certain string. While doing -
find . -mtime 2 -name approve* |xargs grep -l ^"valid data format"
I am not getting the correct results. Can someone provide a better solution?
Thanks,
Vaibhav
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-11-2010 10:58 PM
тАО05-11-2010 10:58 PM
Re: grep ^"string"
find . -mtime 2 -name "approve*" |xargs grep -l ^valid | grep data | grep format
OR
find . -mtime 2 -name "approve*" |xargs grep -l "^valid data format"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-11-2010 11:11 PM
тАО05-11-2010 11:11 PM
Re: grep ^"string"
its working fine on my machine..
[root@vm1 ~]# find . -name "approve*" | xargs grep -i "^valid data format"
./approve:valid data format hai a
./Desktop/approve:valid data format hai a
Gudluck
Prasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-12-2010 12:47 AM
тАО05-12-2010 12:47 AM
Re: grep ^"string"
#!/usr/bin/ksh
while [ $# -gt 0 ]; do
head -1 $1 | grep -q "^valid data format"
if [ $? -eq 0 ]; then
echo $1
fi
shift
done
With this script, you can toss the xargs:
find . -mtime 2 -name "approve*" -exec head_grep +
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-12-2010 06:12 AM
тАО05-12-2010 06:12 AM
Re: grep ^"string"
If, as Dennis interprets your question, you only want results if the first line of any file matches, you could do:
# find . -type f -mtime 2 -name "approve*" -exec perl -we 'while (<>) {if ($.==1) {/^valid data format/ and print $ARGV,":",$_};close ARGV}' {} +
This should be quite efficient since multiple arguments from the find() results are passed to the Perl script. The use of '+' with 'find...-exec {} +' works analogously to 'xargs' in bundling arguments and thus reducing the number of processes created.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-12-2010 04:52 PM
тАО05-12-2010 04:52 PM
Re: grep ^"string"
Except -exec + does a much better job with larger buffers.
find . -exec echo + > find.output
find . | xargs echo > xargs.output
In the above case with ~35 Kb output, there are 1 vs 18 calls to echo.
And xargs(1) has this bogus limitation:
$ find . | xargs -s 40000 echo
xargs: 0 < max-cmd-line-size <= LINE_MAX: -s 40000
And using "-n 40000" isn't fully honored.