String difference in Bash

后端 未结 5 910
借酒劲吻你
借酒劲吻你 2020-12-04 06:31

I\'m trying to find a way to determine the difference between two strings in my script. I could easily do this with diff or comm, but I\'m not dealing with files and I\'d pr

5条回答
  •  伪装坚强ぢ
    2020-12-04 07:06

    Reminds me of this question: How can you diff two pipelines in Bash?

    If you are in a bash session, you could do a:

    diff 

    with < creating anonymous named pipes -- managed by bash -- so they are created and destroyed automatically, unlike temporary files.

    So if you manage to isolate your two different string as part of a command (grep, awk, sed, ...), you can do - for instance - something like:

    diff < grep string1 myFile < grep string2 myFile
    

    (if you suppose you have in your file lines like string1=very_complicated_value and a string2=another_long_and_complicated_value': without knowing the internal format of your file, I can not recommend a precise command)

提交回复
热议问题