-2

I have this:

bar foobar        
111 random111

I want to define $2 so that when compared to $1, it should contain only the differences (non-matching characters):

bar foo
111 random
one-liner
  • 791
  • 1
  • 9
  • 19
  • 2
    Shouldn't your second column contain `foo` and `random`? How is your output showing differences? – jaypal singh May 11 '14 at 05:53
  • 1
    What if $1 contained an RE metacharacter (`.`, `+`, `?`, `*`, etc.)? Would you want it to be taken as that literal character or to perform it's RE function? What if the `$1` contained `o` and $2 `foo` - should the output be `fo` or `f`? – Ed Morton May 11 '14 at 12:59

1 Answers1

1

To print the differences as jaypal points out:

awk '{gsub($1,"",$2)}1' file
bar foo
111 random
Jotne
  • 40,548
  • 12
  • 51
  • 55