Ankit_12 Ankit_12 - 1 month ago 6
Bash Question

Interchange columns using bash

I have a file containing two columns e.g.


  • 10 25

  • 26 38

  • 40 62

  • 85 65

  • 88 96

  • 97 8



I want first column to contain all minimum values and second column containing all maximum values. Something like this:


  • 10 25

  • 26 38

  • 40 62

  • 65 85

  • 88 96

  • 8 97


Answer

Using Python, it is straightforward:

values = [
    (10, 25),
    (26, 38),
    (40, 62),
    (85, 65),
    (88, 96),
    (97, 8),
]

result = [(min(v), max(v)) for v in values]

You get:

[(10, 25), (26, 38), (40, 62), (65, 85), (88, 96), (8, 97)]

Using bash… I don't know:

python -c "<your command here>'
Comments