- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Question using the find command -
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
10-15-2005 08:35 AM
10-15-2005 08:35 AM
How can I do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2005 08:48 AM
10-15-2005 08:48 AM
Re: Question using the find command -
This will check the contents of text files and create a lsit which you can cat later or cat with a script.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2005 09:07 AM
10-15-2005 09:07 AM
Re: Question using the find command -
I don't think that's what I want to do.
Here's another tip on what I want to do.
There are several thousand files on the machine. I need to be able to find certain files amongst those several thousand and cat the results to another file.
for i in `cat /home/me/filestocatout'
do
find $i (against those devices)
cat $i (cat the found files to another file)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2005 10:58 AM
10-15-2005 10:58 AM
Re: Question using the find command -
Now if you already have a list of known-to-be -text files, then your script would look like this:
for MYFILE in $(cat /home/me/filestocatout)
do
cat $MYFILE >> another_file
done
But if this list, filestocatout, contains untested files, your script would have to be changed to something like this:
for MYFILE in $(cat /home/me/filestocatout)
do
file $MYFILE | grep -q text
if [ $? -eq 0 ]
then
cat $MYFILE >> another_file
fi
done
It turns out that most tests in /etc/magic will return the word "text" if the file looks like it contains ASCII text.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2005 11:42 AM
10-15-2005 11:42 AM
Re: Question using the find command -
There are approximately 4000 files total. I need to be able to search through all of these files for specific files. I would like to be able to say something like "for all of the files in the list I specify, do a find on the filename, once found, print the contents of all the files to one large text file so I can search through it for certain command strings".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2005 12:20 PM
10-15-2005 12:20 PM
Re: Question using the find command -
find /somedirectory -type f -name "*-cw.log"
Now you always want to do the above command to determine if the files that were found are indeed the correct ones (and none are overlooked), then you can accomplish the entire task with one line:
find /somedirectory -type f -name "*-cw.log" -exec cat {} \; >> /var/tmp/bigfile
If you know what criteria you need to find within each file, you can add that to the command line:
find /somedirectory -type f -name "*-cw.log" -exec cat {} \; | grep -i -e err -e warn >> /var/tmp/bigfile
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2005 12:31 PM
10-15-2005 12:31 PM
Re: Question using the find command -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2005 12:39 PM
10-15-2005 12:39 PM
Re: Question using the find command -
find /somedirectory -type f -name "*-cw.log" -exec cat {} \; >> /var/tmp/bigfile
to somehow read from a file a list of device names I want to search for. For example, I may need to search for these files which is the hostname of the device with a .cfg extension-
host1.cfg
host2.cfg
host99.cfg
lcartr1.cfg
lcaswitch99.cfg
oregoncat1.cfg
oregonsw99.cfg
The hostnames of the devices don't follow a pattern so I can't say *rtr.cfg or *switch.cfg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2005 12:50 PM
10-15-2005 12:50 PM
Re: Question using the find command -
find /somedirectory -type f -name "*.cfg" -exec cat {} \; >> /var/tmp/bigfile
If you already have a list of the filenames or perhaps a list of the hostnames, then you can use the for-do-done construct to enumerate the filenames and have find locate the specific filename.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2005 01:30 PM
10-15-2005 01:30 PM
Re: Question using the find command -
How on earth would I do what you suggested by using the for-do-done constuct to enumerate the filenames and have the find locate the specific filename then write the contents of the file to largefile?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2005 01:48 PM
10-15-2005 01:48 PM
Re: Question using the find command -
for i in `cat /home/listofhosts`
do
find /somedirectory -type f -name $i -exec cat {} \; >> /var/tmp/bigfile
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2005 02:26 PM
10-15-2005 02:26 PM
SolutionCreate a file with each host name in ie
cat /home/listofhosts
host.1
host.2
host.3
then
for i in `cat /home/listofhosts |awk '{print $1}'`
do
echo "details for host $i" >> /var/tmp/file
find /somedirectory -type f -name "$i.cfg" -exec cat {} \; >> /var/tmp/file
done
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2005 02:49 PM
10-15-2005 02:49 PM
Re: Question using the find command -
Again, Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 02:05 AM
10-17-2005 02:05 AM
Re: Question using the find command -
One small point to mention; if you are going to cat somewhere around 4000 files to /onebigfile, you better be sure you have the disk space available. In other words, don't try to save the result in /onebigfile. Filling up / is not good.
Just my 2cts.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 07:51 AM
10-17-2005 07:51 AM
Re: Question using the find command -
If I understand what you are trying to do I may have a better idea for you.
You have several file names that are scattered about in a file system with 4000 other files.
You want to find all the files with those names and cat them all into one big file.
If thatâ s the case, you donâ t have to find each file individually you can just find all 4000 files once and grep out the names you are looking for and cat those files to your big file
Find . -xdev -print | grep -e "file1" -e "file2" | while read filename
Do
Cat $filename >> $grut.big.file
Done
Or if you have many file names list them in a pattern file and user grep -f patternfile
If thatâ s not what you are trying to do, then ignore this post.
H
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2005 08:43 AM
10-17-2005 08:43 AM
Re: Question using the find command -
I love this forum because each time I need to do something like this, I can come here then come away with a solution.
Again thanks for your response.