diff command in unix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • snowfall
    New Member
    • Aug 2007
    • 56

    diff command in unix

    I need to find the difference of two files and save it in third file and process it..
    But the outpur of diff command is coming with the 'line number - difference' code.

    Eg of my output

    i22,26d21
    < Use the bc program to convert from decimal to hexadecimal.
    < To do so, use the obase command to set the base for output:
    39c34,35
    < See Section 5.6 for more examples of using bc.

    But i want only the lines and not the 'i22,26d21 & < Symbol'..

    Pls help..

    TIA
  • docdiesel
    Recognized Expert Contributor
    • Aug 2007
    • 297

    #2
    Hi,

    if you just need the lines, means their content, you could get them with

    Code:
    diff .... | grep ^\< | sed s/^\<\ //
    But this doesn't give you the information, which line is new nor which one's changed or deleted.

    Regards,

    Bernd

    Comment

    • snowfall
      New Member
      • Aug 2007
      • 56

      #3
      Originally posted by docdiesel
      Hi,

      if you just need the lines, means their content, you could get them with

      Code:
      diff .... | grep ^\< | sed s/^\<\ //
      But this doesn't give you the information, which line is new nor which one's changed or deleted.

      Regards,

      Bernd
      Sorry i dont understand.. Is the syntax like this??

      Code:
      diff file1 file2 > outfile | grep ^\< | sed s/^\<\ //
      pls help...

      Comment

      • docdiesel
        Recognized Expert Contributor
        • Aug 2007
        • 297

        #4
        Hi,

        for just getting the new/changed/deleted lines use

        Code:
        diff  file1.txt file2.txt | grep ^\< | sed s/^\<\ //
        If you need the differences in diff.txt, use
        Code:
        diff  file1.txt file2.txt | tee diff.txt | grep ^\< | sed s/^\<\ //
        Regards,

        Bernd

        Comment

        • snowfall
          New Member
          • Aug 2007
          • 56

          #5
          Originally posted by docdiesel
          Hi,

          for just getting the new/changed/deleted lines use

          Code:
          diff  file1.txt file2.txt | grep ^\< | sed s/^\<\ //
          If you need the differences in diff.txt, use
          Code:
          diff  file1.txt file2.txt | tee diff.txt | grep ^\< | sed s/^\<\ //
          Regards,

          Bernd
          Thanks Bernd.......... ............... ............... ............

          Comment

          Working...