- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Matching text from files within same Tree
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
Discussions
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
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-04-2004 06:44 AM
05-04-2004 06:44 AM
Matching text from files within same Tree
I need my script to look for same text within the specified files. could be multiple files in a single directory.
user should not specify the text.Only the files would be specified.So the script should search for each line of text which it picked from the first file and then look for the same text in other files. Should also give how many times that same text was found e.g
text1.txt has data
Mark
Anthony
script would look for Mark first in all the other files and then give result of hits from other files.Likewise same for anthony.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2004 06:55 AM
05-04-2004 06:55 AM
Re: Matching text from files within same Tree
searchlist="file1 file2 file3"
cat text1.txt | while read line
do
for f in $searchlist
do
count=`grep "$line" $f | wc -l`
if [ $count -gt 0 ]
then
echo "$line was found in $f, $count times"
else
echo "$line was not found in any other files listed"
fi
done
done
please take this segment of code with a grain of salt as it is not tested anywhere.
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2004 06:58 AM
05-04-2004 06:58 AM
Re: Matching text from files within same Tree
for i in `cat first_file`
do
echo "Finding $i"
grep $i * > /tmp/${i}.find
done
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2004 07:52 AM
05-04-2004 07:52 AM
Re: Matching text from files within same Tree
well not sure this is will help
grep pattern
- | wc -l
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2004 07:53 AM
05-04-2004 07:53 AM
Re: Matching text from files within same Tree
#!/usr/bin/perl
opendir(DIR,".");
@files=readdir(DIR);
closedir(DIR);
foreach $file (@files) {
open(INP,"<$file");
while(
chomp;
$hold{$_}{$file}++;
}
close(INP);
}
foreach $text (sort keys %hold) {
@filelist=keys %{$hold{$text}};
print "$text appears\n";
foreach $file (@filelist) {
printf " %8d %s\n",$hold{$text}{$file},$file;
}
}
Would produce a list of
Mark appears
1 text1.txt
4 text2.txt
...
Anthony appears
1 text1.txt
3 text9.txt
...
...
HTH
-- Rod Hills