Hi
i need to have a update for a file that updates only the last modified content from another file....

say for example....if file A is having content like
.
.
.
hatxxxx
catxxxx
ratxxxx
and file B(the file to be updated is having content as
hatxxxx
catxxxx
then file B has to be updated/appended with the last modified content(i.e rat in this case) so as to look like
hatxxxx
catxxxx
ratxxxx
plz help someone with a script.

Recommended Answers

All 2 Replies

Hey there

You can use patch to do that, with diff:

diff fileb filea >DIFF
patch -p0 -i DIFF fileb

You can also do it this way - less hassle and less confusing sometimes:

cat filea fileb|sort -u

There are probably more and better ways to do it depending on exactly what you want (for instance the cat piped to sort will rearrange your data using the default alphabetical sort)

Hope that helps :)

, Mike

printf "%s\n" "$(tail -1 fileA)">>fileB

Or perhaps I misread the question :)

Otherwise:

printf "%s\n" "$(grep -vf fileB fileA)">>fileB
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.