How to copy one columns and print to the last column in unix?

I want to copy column no 3 to the end of column

example :

alter table RECOVER_USR.MPULKIXD rename to
alter table RECOVER_USR.CS_ADV_PROMO rename to
alter table RECOVER_USR.BCH_HISTORY_TABLE rename to
alter table BILLOPS.HISHAM_DATAPLUS_FINAL rename to
alter table BILLOPS.HISHAM_DATALITE_FINAL rename to
alter table BILLOPS.HISHAM_UNMATCHPOST1 rename to
alter table BILLOPS.HISHAM_POSTCODE rename to
alter table BILLOPS.HISHAM_GPRSUNLIMITED2 rename to
alter table BILLOPS.HISHAM_ORDERTRAILER rename to

output :

alter table RECOVER_USR.MPULKIXD rename to RECOVER_USR.MPULKIXD
alter table RECOVER_USR.CS_ADV_PROMO rename to RECOVER_USR.CS_ADV_PROMO
alter table RECOVER_USR.BCH_HISTORY_TABLE rename to RECOVER_USR.BCH_HISTORY_TABLE
alter table BILLOPS.HISHAM_DATAPLUS_FINAL rename to BILLOPS.HISHAM_DATAPLUS_FINAL
alter table BILLOPS.HISHAM_DATALITE_FINAL rename to BILLOPS.HISHAM_DATALITE_FINAL
alter table BILLOPS.HISHAM_UNMATCHPOST1 rename to BILLOPS.HISHAM_UNMATCHPOST1
alter table BILLOPS.HISHAM_POSTCODE rename to BILLOPS.HISHAM_POSTCODE
alter table BILLOPS.HISHAM_GPRSUNLIMITED2 rename to BILLOPS.HISHAM_GPRSUNLIMITED2
alter table BILLOPS.HISHAM_ORDERTRAILER rename to BILLOPS.HISHAM_ORDERTRAILER

 
nawk '{print $0,$3}' File >> newfile
$ ruby -ane 'print "#{$_.chomp} #{$F[2]}\n"' file

hi all,

i'm sorry. i want something output like this

alter table RECOVER_USR.MPULKIXD rename to MPULKIXD
alter table RECOVER_USR.CS_ADV_PROMO rename to CS_ADV_PROMO
alter table RECOVER_USR.BCH_HISTORY_TABLE rename to BCH_HISTORY_TABLE
alter table BILLOPS.HISHAM_DATAPLUS_FINAL rename to HISHAM_DATAPLUS_FINAL
alter table BILLOPS.HISHAM_DATALITE_FINAL rename to HISHAM_DATALITE_FINAL
alter table BILLOPS.HISHAM_UNMATCHPOST1 rename to HISHAM_UNMATCHPOST1
alter table BILLOPS.HISHAM_POSTCODE rename to HISHAM_POSTCODE
alter table BILLOPS.HISHAM_GPRSUNLIMITED2 rename to HISHAM_GPRSUNLIMITED2
alter table BILLOPS.HISHAM_ORDERTRAILER rename to HISHAM_ORDERTRAILER

 
nawk -F . '{print $2 }' File |paste File - |nawk '{$7="";$8="";$9=""}1' >>newfile

Simplest way I can think of:

awk '{split($3,a,".") ; print $0,a[2]}' <file>

---------- Post updated at 12:08 PM ---------- Previous update was at 12:05 PM ----------

malikshahid85, could you please explain the "1" just before the closure of your last nawk statement? I've seen that in a few different (,n,g)awks, but I've never been clear on what that does. Many thanks in advance.

we use 1 or any other digit to print only one blank space between the fields if the fields have more than one space.

So it sounds like a "trim" type function. Strangely, though, when I tried it on my system, removal of the "1" suppressed all output.

more simple

awk -F "[ .]" '{print $0,$4}' infile