Skip to main content
3 of 11
added 83 characters in body
lcd047
  • 7.4k
  • 1
  • 24
  • 33

The sed way:

sed -E ' s/^(([ \t]*-?[ \t]*[0-9]+[ \t]+[0-9]+)*)[ \t]+-?[ \t]*[0-9]+/\1/; s/[0-9]+[ \t]+([0-9]+)/\1/g' 

Output:

-2 4 -9 3 -5 -11 

The first expression kills the trailing column if there are an odd number of columns. It does that by looking for 0 or mode pairs <number> <number>, where the first number can be negative.

lcd047
  • 7.4k
  • 1
  • 24
  • 33