-1

I have 2 files:

  • File1:

    DX 100860599215|732512737|00002|40|1|20220105|20220105|20220523|31014280|5892720|36907000|1|20220105|40|20|D|
    
  • File2

    DX 100860599216|732512737|00002|40|1|20220105|20220105|20220523|31014280|5892720|36907000|1|20220105|40|20|D|
    

I want to get only the differing string from this and not full line

100860599215
100860599216

any help here pls

1 Answer 1

1

I came with this ugly solution

diff <(tr  '|'  \\n < file1 ) <(tr  '|' \\n < file2)

giving

1c1
< DX 100860599215
---
> DX 100860599216

where

  • tr '|' \\n < file1 flatten file each '|' is turn to a new line
  • <( ) construct make a pseudo file from inside command

as per comment, replacing tr '|' \\n < file1 by tr ' |' '\n\n' < file1 give a result closer to expected result.

diff <(tr  ' |'  '\n\n' < file1 ) <(tr  ' |' '\n\n' < file2)
2c2
< 100860599215
---
> 100860599216
2
  • If you use tr ' |' '\n\n' you split the initial DX off too, which will give you something that looks more like what the user wants. Commented Dec 12, 2022 at 12:45
  • @Archemar, if OP literally wants exactly what he stated '100860599215' and '100860599216' (without 'DX' and 'space' between them), we can do this with awk and/or sed/cut: diff <(tr '|' \\n < file1 ) <(tr '|' \\n < file2) | awk 'NF==3 {print $3}'. Of course if pattern with 'DX' 'space' and 'string' is allways the same... Commented Dec 12, 2022 at 13:13

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.