Hi,
Have been studying my Bash manual but for the life of me I still cannot work out the commands to use to 'merge' 2 x text files together..
Could some kind soul provide a few written hints as to how I can do this in "bash" please..
I have 2 x text files with almost the same content - however one may be updated when any new prog is installed - the other is a 'fixed' one which includes any 'personalised' entries that I don't want to be changed by "updates"..
So have determined that the best way is to have 2 x text files and "merge" them at specific times so as the resulting file includes the 'updates' but also keeps my 'personalised' entries unchanged as well..
Any guidance would be much appreciated..
.
.
.
bash/ash - commands to merge two similar text files (SOLVED)
- craftybytes
- Posts: 298
- Joined: Fri 17 Nov 2006, 10:32
- Location: QLD AUSTRALIA
bash/ash - commands to merge two similar text files (SOLVED)
Last edited by craftybytes on Tue 13 Mar 2007, 01:46, edited 1 time in total.
3 x boot:- ASROCK VIA 'all-in-one' m/b; AMD Duron 1.8Ghz+; 1.0GB RAM; 20GB hdd (WinXP Pro); 80GB hdd (MEPIS 3.4-3/Puppy v2.15CE Frugal); 1GB USB pendrive (Puppy 2.15CE Frugal); CD/DVDRW; 17" LCD monitor; HSF 56k modem... MEPIS is great.. Puppy ROCKS..
I think you need to specify the problem more clearly.
File A is static
File B contains just updates or File B is a copy of A with some extra lines/some lines changed/some lines with extra entries on the end
I want to merge them into file C by
appending all lines in B to the end of A
overwriting specific lines in A with those in B
appending data in line 7 in B to the end of line 7 in A
There are a lot of possibilities, why don't you just post two example input files and the output you expect.
If you just want to read up on it yourself. The answer probably involves using sed and possibly awk, hairy beasts.
File A is static
File B contains just updates or File B is a copy of A with some extra lines/some lines changed/some lines with extra entries on the end
I want to merge them into file C by
appending all lines in B to the end of A
overwriting specific lines in A with those in B
appending data in line 7 in B to the end of line 7 in A
There are a lot of possibilities, why don't you just post two example input files and the output you expect.
If you just want to read up on it yourself. The answer probably involves using sed and possibly awk, hairy beasts.
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]
you'll be able to tell i'm not a programmer,but here goes:
easy enough to merge them :
maybe also sort the output file
i'm not near a puppy machine so am not sure whether bash has this, but filtering the resultant file to kill off the dupes you can use
Check the man page for the option you'll need.
wrap all this up in tidy script that deletes & renames the intermediate workfiles.
it's how i would do it as a q&d but effective job, but you could also write a nice awk script to do this.
hope this helps
paul
easy enough to merge them :
Code: Select all
# cat file1 file2 > file3
i'm not near a puppy machine so am not sure whether bash has this, but filtering the resultant file to kill off the dupes you can use
Code: Select all
# uniq file3
wrap all this up in tidy script that deletes & renames the intermediate workfiles.
it's how i would do it as a q&d but effective job, but you could also write a nice awk script to do this.
hope this helps
paul
- craftybytes
- Posts: 298
- Joined: Fri 17 Nov 2006, 10:32
- Location: QLD AUSTRALIA
Thanks guys for the pointers..
Actually after I posted I tried 'google' to see what came up - well dog gone - many ways to do it - so have seived it down to 3 or 4 ways that more suit what I want and now will try them ..
Google does have its uses now and then ..
BTW - puppy does have TkDiff - for comparing 2 files - but does not have a combined 'diff' & 'merge' prog that will do what I need..
Thanks for the help..
Actually after I posted I tried 'google' to see what came up - well dog gone - many ways to do it - so have seived it down to 3 or 4 ways that more suit what I want and now will try them ..
Google does have its uses now and then ..
BTW - puppy does have TkDiff - for comparing 2 files - but does not have a combined 'diff' & 'merge' prog that will do what I need..
Thanks for the help..
3 x boot:- ASROCK VIA 'all-in-one' m/b; AMD Duron 1.8Ghz+; 1.0GB RAM; 20GB hdd (WinXP Pro); 80GB hdd (MEPIS 3.4-3/Puppy v2.15CE Frugal); 1GB USB pendrive (Puppy 2.15CE Frugal); CD/DVDRW; 17" LCD monitor; HSF 56k modem... MEPIS is great.. Puppy ROCKS..