General

Re: Question using the find command -

 
SOLVED
Go to solution
Rob Johnson_3
Regular Advisor

Re: Question using the find command -

I guess it's gonna look something like:

for i in `cat /home/listofhosts`
do
find /somedirectory -type f -name $i -exec cat {} \; >> /var/tmp/bigfile
done

lawrenzo
Trusted Contributor
Solution

Re: Question using the find command -

so if you know the host names you could do this.

Create 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
hello
Rob Johnson_3
Regular Advisor

Re: Question using the find command -

Ok. Thanks everyone for your input. I think I can make this work. I don't have a unix box here at home so I can't test this out until Monday.

Again, Thank you!
Mark Ellzey
Valued Contributor

Re: Question using the find command -

Rob,

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
Howard Marshall
Regular Advisor

Re: Question using the find command -

Rob,

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
Rob Johnson_3
Regular Advisor

Re: Question using the find command -

Thanks for your response. Actually, I was able to run put a script together from the previous posts and it worked quiet well. I'm gonna stick with it.
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.