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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to copy one columns and print to the last column in unix?
# 1  
Old 09-29-2010
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
# 2  
Old 09-29-2010
Quote:
Originally Posted by arifahel
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


Code:
 
nawk '{print $0,$3}' File >> newfile

# 3  
Old 09-29-2010
Code:
$ ruby -ane 'print "#{$_.chomp} #{$F[2]}\n"' file

# 4  
Old 09-30-2010
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
# 5  
Old 09-30-2010
Quote:
Originally Posted by arifahel
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

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

# 6  
Old 09-30-2010
Simplest way I can think of:

Code:
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.
# 7  
Old 09-30-2010
Quote:
Originally Posted by treesloth
Simplest way I can think of:

Code:
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to copy a column of multiple files and paste into new excel file (next to column)?

I have data of an excel files as given below, file1 org1_1 1 1 2.5 100 org1_2 1 2 5.5 98 org1_3 1 3 7.2 88 file2 org2_1 1 1 2.5 100 org2_2 1 2 5.5 56 org2_3 1 3 7.2 70 I have multiple excel files as above shown. I have to copy column 1, column 4 and paste into a new excel file as... (26 Replies)
Discussion started by: dineshkumarsrk
26 Replies

2. UNIX for Beginners Questions & Answers

Copy columns from one file into another and get sum of column values and row count

I have a file abc.csv, from which I need column 24(PurchaseOrder_TotalCost) to get the sum_of_amounts with date and row count into another file say output.csv abc.csv- UTF-8,,,,,,,,,,,,,,,,,,,,,,,,, ... (6 Replies)
Discussion started by: Tahir_M
6 Replies

3. UNIX for Dummies Questions & Answers

Want the UNIX code - I want to sum of the 1st column wherever the first 2nd and 3rd columns r equal

I have the code for the below things.. File1 has the content as below 8859 0 subscriberCreate 18 0 subscriberPaymentMethodChange 1650 0 subscriberProfileUpdate 7668 0 subscriberStatusChange 13 4020100 subscriberProfileUpdate 1 4020129 subscriberStatusChange 2 4020307 subscriberCreate 8831... (5 Replies)
Discussion started by: Mahen
5 Replies

4. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

Combine columns from many files but keep them aligned in columns-shorter left column issue

Hello everyone, I searched the forum looking for answers to this but I could not pinpoint exactly what I need as I keep having trouble. I have many files each having two columns and hundreds of rows. first column is a string (can have many words) and the second column is a number.The files are... (5 Replies)
Discussion started by: isildur1234
5 Replies

6. UNIX for Advanced & Expert Users

Copy a column to another column in UNIX fixedwidth file

Hi All, I have a fixedwidth file of length 3000. Now i want to copy a column of 4 chars i.e( length 1678-1681) to column 1127 – 1171 to the same file. Please let me know how can i achive using a single command in fixed width file. Also source column length is 4 chars and target column length... (4 Replies)
Discussion started by: kiranparsha
4 Replies

7. UNIX for Dummies Questions & Answers

how to print the column that contains a string in delimited file in unix

Hi Team, I have a requirement to print the column or find the column number of a particular string in delimited (;) file. Ex: aaa;bbb;ccc;rrr;mmm; gggg;rrr;mmmm;ssss;eee;aaa; ccc;gggg;tttt;bbbb;dddd;ggggg;rrr; my file contains 1000+ rows like above example with semicolon... (3 Replies)
Discussion started by: baskivs
3 Replies

8. Shell Programming and Scripting

Need to find a column from one file and print certain columns in second file

Hi, I need helping in finding some of the text in one file and some columns which have same column in file 1 EG cat file_1 aaaa bbbb cccc dddd eeee fffff gggg hhhh cat file_2 aaaa,abcd,effgh,ereref,name,age,sex,........... bbbb,efdfh,erere,afdafds,name,age,sex.............. (1 Reply)
Discussion started by: jpkumar10
1 Replies

9. UNIX for Dummies Questions & Answers

Copy column to another column in unix

Dear Gurus, I have a unix file 2 columns (# delimited) with the following data: ZTXX_CTBR1-ZBRAN1#ZTXX_CTBR1-ZBRAN_DESC# 01#CASH & CARRY# 02#DRUGSTORE - RX# 04#SUPERMARKET# 05#HYPERMARKET# 17#DRUGSTORE - NO RX# I would like to have a code that will do 2 things: 1. Delete the header... (16 Replies)
Discussion started by: chumsky
16 Replies

10. UNIX for Dummies Questions & Answers

Print last 4 columns (variable column #)

I have rows of data with variable number of columns. Is there an easy way to print out the last 4 columns or rather the 4th and 3rd last column? data looks like this: 24 20:51 N 9 10.00 Overcast OVC110 27 11 30.04 1017.7 24 19:51 N 7 10.00 Mostly Cloudy BKN110 28 15... (19 Replies)
Discussion started by: Da_Duck
19 Replies
Login or Register to Ask a Question