On Tue, 2008-01-29 at 18:17 -0800, Nelson Serafica wrote:
> I need to create a script where if there are new alias created, it
> will dump to a file called address.txt.

ok, i don't do that, so i don't know enough details to discuss
the specific problem.


> Can diff recognize the new added text and removed text?

however, *this* i do know about.

when you run diff with two filenames (previous and current)

it'll show the differences.  the lines that start with a
greater than sign (>) indicate that the line is in the
file on the right (e.g., if you do:

diff old_file.txt new_file.txt

then lines that start with > mean that the line was ADDED
in the new file. it wasn't in the old file.  similarly,
lines that start with < mean that the line was in the old
file and was removed in the new file.

changes are a little tricky.  youll have a < and a > 
one after the other and you need to notice that the two
lines have essentially the same data with some data changed.
e.g.,

< tiger was here
> tiger wasn't here

indicates that the line was changed (n't) inserted.

diff can get confused if the file is very large and a line
was moved from one part of the file to another part.  for
something like /etc/aliases though, where order doesn't 
matter, what you could do is sort the files before doing
the diff (or sort the new file, since the old file would
have already been sorted in the previous run). that can
help diff a bit.

> Or do I need to use other language? Or there are other commands
> similar to diff? I tried a create script as simple as possible that's
> why I'm using bash.

for something similar (but much more complex) i've done:

A. store the versions in version control (svn) and then just
   svn commit in cron.  if there are no differences, the 
   commit won't do anything.

   this can get a little tricky if you get conflicts though.
   you probably won't with /etc/alias since there won't be
   multi row records and you'll sort.  but in the past, when
   there was a conflict the script would detect that and then
   just automatically use the latest file and resolve.

the advantage of this is, you don't need to worry about
file renames, atomicity, etc.

tiger

_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
[email protected] (#PLUG @ irc.free.net.ph)
Read the Guidelines: http://linux.org.ph/lists
Searchable Archives: http://archives.free.net.ph

Reply via email to