toky
toky

Reputation: 119

Unix sed command sort and compare

Lets say i have a file name demo which contains an essay. how can i sort a the file alphabetically and then compare it the result with a file name demo2 using sed or anything else.

Upvotes: 1

Views: 1266

Answers (3)

chrisaycock
chrisaycock

Reputation: 37930

Here's a one-liner:

diff <(sort demo1) <(sort demo2)

Upvotes: 2

icyrock.com
icyrock.com

Reputation: 28608

Probably best to use diff:

for this purpose. Something like this:

sort demo > demo_sorted
sort demo2 > demo2_sorted
diff demo_sorted demo2_sorted

You can read starting from here

about the different versions of the output you can produce.

Upvotes: 0

Diego
Diego

Reputation: 18359

First, sort both files, then diff them:

sort demo1 > demo1sorted
sort demo2 > demo2sorted
diff demo1sorted demo2sorted

Upvotes: 0

Related Questions