Duplicate third column to every line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Duplicate third column to every line
# 1  
Old 05-22-2013
Duplicate third column to every line

Dear All,

I have file input like this:

Code:
INP901 5173    4114
INP902 5227    
INP903 5284    
INP904 5346    
INP905 5400    
INP906 5456    
INP907 5511    
INP908 5572    
INP909 5622    
INP910 5678    
INP911 5739    
INP912 5796    
INP913 5845    
INP914 5910    
INP915 5965    
INP916 6027    
INP917 6082    
INP918 6129    
INP919 6182    
INP920 6235    
INP921 6290    
INP922 6357    
INP923 6406    
INP924 6466    
INP925 6521    
INP926 6572    
INP927 6637    
INP928 6697    
INP929 6757    
INP930 6812    
INP931 6856    
INP932 6909    
INP933 6962    
INP934 7011    
INP935 7071    
INP936 7131    
INP937 7195    
INP938 7243    
INP939 7298

Desired output:
Code:
INP901 5173    4114
INP902 5227    4114
INP903 5284    4114
INP904 5346    4114
INP905 5400    4114
INP906 5456    4114
INP907 5511    4114
INP908 5572    4114
INP909 5622    4114
INP910 5678    4114
INP911 5739    4114
INP912 5796    4114
INP913 5845    4114
INP914 5910    4114
INP915 5965    4114
INP916 6027    4114
INP917 6082    4114
INP918 6129    4114
INP919 6182    4114
INP920 6235    4114
INP921 6290    4114
INP922 6357    4114
INP923 6406    4114
INP924 6466    4114
INP925 6521    4114
INP926 6572    4114
INP927 6637    4114
INP928 6697    4114
INP929 6757    4114
INP930 6812    4114
INP931 6856    4114
INP932 6909    4114
INP933 6962    4114
INP934 7011    4114
INP935 7071    4114
INP936 7131    4114
INP937 7195    4114
INP938 7243    4114
INP939 7298    4114

Thanks for advance.

Attila
# 2  
Old 05-22-2013
try

Code:
awk 'NR==1{S=$NF} NR>1{$(NF+1)=S}1' file

This User Gave Thanks to pamu For This Post:
# 3  
Old 05-22-2013
I was getting some error with @pamu's solution. After some modification, it did worked for me:

awk 'NR==1{S=$NF;print}NR>1{print $0 S}' testFile

regards,
juzz4fun
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Duplicate and change a column

Hi, I have a file with list of items: a b c I would like to run a 1-liner (awk/perl) to duplicate and change the value of the existing column, i.e.: a a b b c c I can duplicate with awk: awk '{print $1 " " $1 }' but couldn't figure out how to do the character change, your help is... (5 Replies)
Discussion started by: yan1
5 Replies

2. Shell Programming and Scripting

Find duplicate values in specific column and delete all the duplicate values

Dear folks I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Discussion started by: sajmar
4 Replies

3. Shell Programming and Scripting

Honey, I broke awk! (duplicate line removal in 30M line 3.7GB csv file)

I have a script that builds a database ~30 million lines, ~3.7 GB .cvs file. After multiple optimzations It takes about 62 min to bring in and parse all the files and used to take 10 min to remove duplicates until I was requested to add another column. I am using the highly optimized awk code: awk... (34 Replies)
Discussion started by: Michael Stora
34 Replies

4. Shell Programming and Scripting

awk to sum a column based on duplicate strings in another column and show split totals

Hi, I have a similar input format- A_1 2 B_0 4 A_1 1 B_2 5 A_4 1 and looking to print in this output format with headers. can you suggest in awk?awk because i am doing some pattern matching from parent file to print column 1 of my input using awk already.Thanks! letter number_of_letters... (5 Replies)
Discussion started by: prashob123
5 Replies

5. Shell Programming and Scripting

Help with duplicate column 1 data

Input file Q6GZV8 AY548484>AAT09676.1>YP_031595.1>2947737>CLSP2512393 P0C9E9 AY261366 P0C9K3 AY261361>IPR004848>PF01639 P0C9I4 AY261363>IPR004848 Desired output file Q6GZV8 AY548484 Q6GZV8 AAT09676.1 Q6GZV8 YP_031595.1 Q6GZV8 2947737 Q6GZV8 CLSP2512393 P0C9E9 AY261366... (3 Replies)
Discussion started by: perl_beginner
3 Replies

6. Shell Programming and Scripting

1st column,2nd column on first line 3rd,4th on second line ect...

I need to take one column of data and put it into the following format: 1st line,2nd line 3rd line,4th line 5th line,6th line ... Thanks! (6 Replies)
Discussion started by: batcho
6 Replies

7. UNIX for Dummies Questions & Answers

awk: duplicate a column into a new one

Hi ! I have a "|" delimited file: field 1|field2|field3|field4 AAA|BBB|CCC|DDD EEE|FFF|GGG|HHH Using awk, I need to duplicate the 2nd column and print it into a 5th new column, like that: output: field 1|field2|field3|field4|field 2 AAA|BBB|CCC|DDD|BBB EEE|FFF|GGG|HHH|FFF Thanks... (1 Reply)
Discussion started by: lucasvs
1 Replies

8. Shell Programming and Scripting

duplicate a column with awk

I have some tab delimited data and I need to duplicate the second column. It seems like I should just be able to do something simple in awk like, awk '{ print $1, $2, $2, $3 }' (the second field is the one that needs to be duplicated) but I'm not sure how to print from $3 to the end of the... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

9. Shell Programming and Scripting

Read duplicate column, then generate a single line

Dear experts, How to generate the result listed below ? Input file: col1col2col3Aname1size1Aname2size2Aname3size1Bname4size3Bname5size5Cname6size8Cname7size6Cname8size9Cname9size11Cname10size16 What I want is: Aname1, size1name2, size2name3, size1Bname4,size3name5, size5Cname6,... (1 Reply)
Discussion started by: tojzz
1 Replies

10. Shell Programming and Scripting

Remove duplicate line detail based on column one data

My input file: AVI.out <detail>named as the RRM .</detail> AVI.out <detail>Contains 1 RRM .</detail> AR0.out <detail>named as the tellurite-resistance.</detail> AWG.out <detail>Contains 2 HTH .</detail> ADV.out <detail>named as the DENR family.</detail> ADV.out ... (10 Replies)
Discussion started by: patrick87
10 Replies
Login or Register to Ask a Question