Friday 4 May 2012

awk command to merge columns from two separate files into single file?

Here's a nifty shell command to concatenate columns or combine columnar files (tab, space, comma separated) by using the pr command 

NAME
       pr - convert text files for printing

SYNOPSIS
       pr [OPTION]... [FILE]...

DESCRIPTION
       Paginate or columnate FILE(s) for printing.

       Mandatory arguments to long options are mandatory for short options too.


credit:colucix
http://www.linuxquestions.org/questions/linux-newbie-8/awk-command-to-merge-columns-from-two-separate-files-into-single-file-522016/#post2598889

Code:
    > cat file1  one two three  one two three  one two three  one two three    > cat file2  four five six  four five six  four five six  four five six    > pr -m -t -s\  file1 file2 | gawk '{print $4,$5,$6,$1}'  four five six one  four five six one  four five six one  four five six one

No comments:

Post a Comment

Datanami, Woe be me