Just as an addition to answers that suggest to duplicate the columns and then to do cut
. For duplication, paste
etc. will work only for files, but not for streams. In that case, use sed
instead.
cat file.txt | sed s/'.*'/'&\t&'/ | cut -f2,3
This works on both files and streams, and this is interesting if instead of just reading from a file with cat
, you do something interesting before re-arranging the columns.
By comparison, the following does not work:
cat file.txt | paste - - | cut -f2,3
Here, the double stdin placeholder paste
does not duplicate stdin, but reads the next line.