rose
rose

Reputation: 137

Remove extra characters from diff output

I have the below output from unix:

$ diff -y --suppress-common-lines backup.txt newfile.txt
                                                              > `jjj' int,

i need only jjj : int as output. tried the below didnt work as expected:

$ diff -y --suppress-common-lines backup.txt newfile.txt | grep -i '>' |tr -d '[>]'  |sed 's/,//g'

Upvotes: 1

Views: 124

Answers (2)

not2qubit
not2qubit

Reputation: 16912

The most common reasons for this not working are:

  1. Your file is encoded as a non ASCII file, most commonly in UTF-8.
    (Save the text files as ASCII.)
  2. You are running this in a command shell with colors.
    (Colors are actually ANSI characters and messes up sed.)
  3. You have encoded your file with a different EOL than used in your *nix OS (\n), such as \r\n (Windows) or \r (MacOS).
  4. There are hidden TAB (\t) characters in the file.

After you have fixed the above, try this:

diff -Ewy -r --suppress-common-lines -aB -W 512 file.txt file2.txt | tr -d '[>]'

Upvotes: 1

Dudi Boy
Dudi Boy

Reputation: 4865

suggesting to try gawk script:

diff -y --suppress-common-lines backup.txt newfile.txt | gawk '{print $1 ":" $2}' FPAT="[[:alnum:]]+"

Upvotes: 1

Related Questions