0

I have this file

1  you
3  me
2  their
4  us

this pipe works fine (it order first column by number, second by letters) is a pipe of another user found here

paste <(awk '{print $1}' file.txt | sort -k1n) <(awk '{print $2}' \
file.txt | gsort -V)

but now use a word with spaces

1  "and me"
3  me
2  their
4  us

The same command produce this

1   me
2   their
3   us
4   "and

How to produce a result like this?

1   and me
2   their
3   us
4

I have tried:

  • remove number 4

  • use "and me"

  • use 'and me'

But give me the incorrect result

1
  • awk and sort use any whitespace as separator by default, so if your fields contain something else too, you'd need to set another separator. E.g. tab. Or, if it's a fixed-width field, use cut. So depends, what's the input format? Commented Feb 6 at 7:43

1 Answer 1

1

Going off of your code, just need to tweak the awk part a little bit:

paste <(awk '{print $1}' file_name | sort -k1n) <(awk '{$1=""; gsub(/^[ \t]*|"/,""); print $0}' file_name | sort -V)

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.