Copy column to another column in unix


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Copy column to another column in unix
# 1  
Old 09-07-2011
Copy column to another column in unix

Dear Gurus,

I have a unix file 2 columns (# delimited) with the following data:

Code:
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 row
2. Copy the second column into a third column

The output file should look like below:


Code:
01#CASH & CARRY#CASH & CARRY#
02#DRUGSTORE - RX#DRUGSTORE - RX#
04#SUPERMARKET#SUPERMARKET#
05#HYPERMARKET#HYPERMARKET#
17#DRUGSTORE - NO RX#DRUGSTORE - NO RX#

Any help will be much appreciated.

Thanks,

Chukwuma

Last edited by vgersh99; 09-07-2011 at 11:17 AM.. Reason: code tags, please!
# 2  
Old 09-07-2011
Code:
 
awk -F# '{if(NR!=1)print $0$2FS}' file

# 3  
Old 09-07-2011
Thank you for your reply. The first part worked with the removal of the header, however the second column was not copied copied. Here is the output I got:

Code:
01#CASH & CARRY##
02#DRUGSTORE - RX##
04#SUPERMARKET##
05#HYPERMARKET##
17#DRUGSTORE - NO RX##

Thanks for your help
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 09-07-2011 at 11:15 AM.. Reason: code tags, please!
# 4  
Old 09-07-2011
Code:
 nawk -F'#' 'FNR>1{print $0 $2 FS}' myFile

# 5  
Old 09-07-2011
I can confirm too on a linux machine:
Code:
 awk -F\# '{if(NR!=1)print $0 $2 FS}' yourTestFile

works correctly
# 6  
Old 09-07-2011
Hi vgersh99,
Thanks for the reply. unfortunately the third column is still blank after executing the script. Any other ideas?

Thanks,

Chukwuma

---------- Post updated at 08:33 AM ---------- Previous update was at 08:30 AM ----------

Hello Cicorino,

Same issue. Copied column is still blank.

Thanks,

Chukwuma
# 7  
Old 09-07-2011
please tell us both awk and os version details
 
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

UNIX script to compare 3rd column value with first column and display

Hello Team, My source data (INput) is like below EPIC1 router EPIC2 Targetdefinition Exp1 Expres rtr1 Router SQL SrcQual Exp1 Expres rtr1 Router EPIC1 Targetdefinition My output like SQL SrcQual Exp1 Expres Exp1 Expres rtr1 Router rtr1 Router EPIC1 Targetdefinition... (5 Replies)
Discussion started by: sekhar.lsb
5 Replies

3. Shell Programming and Scripting

Locate the files in the first column and copy the files in 2nd column

#cat data.txt file1 folder1 file2 thisforfile2 file3 thisfolderforfile3 lata4 folder4 step 1: create the folder first in column 2 for i in `awk '{print $2}' data.txt` do mkdir /home/data/$i done step 2: locate the files in column1 and stored them into a file for i in... (17 Replies)
Discussion started by: kenshinhimura
17 Replies

4. 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

5. Shell Programming and Scripting

Copy column string and put in different column

Hello Here is my input: SU3902 SU3902A NS29C (10) (00) Q1J1 0 SU3902 SU3902B VLR05 (20) (02) Q2H1 4 SU3902 SU3902C NBR22 (30) (06) Q3R5 8 SU3904 SU39047 NSV19 (11) (09) Q4k6 2 SU3904 SU39048 LB231 (12) (05) Q5k1 6 SU3904 SU39049 11VLT (13) (08) Q10C1 10 SU3904 SU3904A 25R05 (15) (06)... (3 Replies)
Discussion started by: pareshkp
3 Replies

6. Shell Programming and Scripting

for each different entry in column 1 extract maximum values from column 2 in unix/awk

Hello, I have 2 columns (1st column has multiple entries but the corresponding values in the column 2 may be the same or different.) however I want to extract unique values for each entry in column 1 by assigning the max value from column 2 SDF4 -0.211654 SDF4 0.978068 ... (1 Reply)
Discussion started by: Diya123
1 Replies

7. UNIX for Dummies Questions & Answers

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... (8 Replies)
Discussion started by: arifahel
8 Replies

8. Shell Programming and Scripting

Copy the data column to adjacent column

Hi, i have file which contains only one record like below a|b|c|.... The no of columns is not known. The expected output is as below: a|a|b|b|c|c|... Please provide me your suggestions. OS: unix Thanks, Selva (7 Replies)
Discussion started by: bharathappriyan
7 Replies

9. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

10. UNIX for Advanced & Expert Users

extracting/copy a column into a new column

Hello, Anybody out there knows how to copy a column data into a blank column using unix command? Thanks (1 Reply)
Discussion started by: folashandy
1 Replies
Login or Register to Ask a Question