LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 03-09-2010, 08:47 AM   #1
amit_pansuria
Member
 
Registered: Sep 2006
Posts: 73

Rep: Reputation: 15
how do merge diff of two files on linux


suppose I have two files which contains following parameter

(1) file1: test1

LOG_OUT:YES

(2) file 2: test2

LOG_OUT:NO
TIME:40

Now I want to find the diff and merged into file 2 i.e. test2 so that file test2 contains the following parameter

test2

LOG_OUT:YES
TIME:40

Can any one have any idea how do I achieve this ?? any command for mergring and achieving above

I m using RHEL 4.7


Regards,
Amit P
 
Old 03-09-2010, 10:10 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
That seems a little disconnected.

If all you want to do is change entry in second file to "YES" from "NO" sed would be a good way to go. There is no commonality between file1 and file 2 on which to determine what to change the entry to. Does each file in fact only contain one record as in your example? If not then that lack of commonality means there's no automated way to do what you want.

If each file only has one record then you could do it by doing something testing the value of both files for the answer to LOG_OUT: and use that as the basis for what you do:

Code:
LO_FILE1=$(grep LOG_OUT file1 |awk -F: '{print $2}')
sed -e s/LOG_OUT:NO/LOG_OUT:$LO_FILE1/ -e s/LOG_OUT:YES /LOG_OUT:$LO_FILE1/ file2
The first line gets the value following LOG_OUT: from file1.
The second line substitutes that value from file1 in file2 regardless of whether current values is YES or NO in file2. (You could refine the script by actually testing for the current value and only substituting if it were different but the above is a quick and dirty way that would work.)
 
Old 03-09-2010, 10:11 AM   #3
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
hmm i dont know specific syntax but you would more then likely be looking for something along the lines of grep sed and/or awk , more then likely piping a few together (with a |) then redirecting the output into a third file with a >
use man grep, sed or awk to find out about the commands
sorry if i wasnt too helpful

other commands like wc (word count) might help as well
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
merge wav files linuxhippy Slackware 11 08-02-2021 12:41 AM
Merge tar files ust Linux - Newbie 6 06-20-2011 05:02 PM
LXer: An easy way to Spilt or Merge PDF Files in Linux LXer Syndicated Linux News 0 04-17-2009 03:00 PM
compare two files and merge nelex Programming 5 02-25-2009 08:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 04:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration