TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TCLUG:21204] Question on Bourne shell script.
You have two files, one is the list of all files and the other is a list
of files to exclude?
all_files is the 1st, exclude is the second:
for a in `cat exclude`
do
grep -v "$a" all_files > temp.$$
cp temp.$$ all_files
done
That's off the top of my head. There's a much easier way to do this but
it eludes me right now (actually there are tons of ways to do this, the
beauty of bash!).
Test this first, I just pulled it straight out of thin air and haven't
checked it.
Adam Maloney
Systems Administrator
Sihope Communications
On Mon, 11 Sep 2000, Mike Glaser wrote:
> I am working on a shell script to run a tape backup for one of my servers and I
> have a small problem.
>
> Since I am using cpio, I first generate list of all files on the server with the find
> command. Then I want to go back and remove any directories that meet a
> certain pattern (like ' ^ \ /proc \ / ' ) that is included in another 'exclude' file. I
> thought of one way to do that using 'grep -v .... > somefile.txt'
>
> My problem is, how do I read in the list of excluded directories from a file and
> pass that to grep? I guess I don't understand redirection and shell
> programming enough to solve my problem. I could figure out a solution with
> Perl, but I must write te code in a bash script.
>
> This is what I have now, but it doesn't work...
> grep -v file.txt < cat exclude_list.txt > new_shorter_file.txt
>
> If anyone could help me out I would appreciate it!
> Thank-you,
> Mike Glaser
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tclug-list-unsubscribe@mn-linux.org
> For additional commands, e-mail: tclug-list-help@mn-linux.org
>
>