Awk: duplicate column and print remaining as is


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk: duplicate column and print remaining as is
# 1  
Old 12-06-2017
Awk: duplicate column and print remaining as is

Hello there

I'd like to make a copy of 2nd column and have it printed in place of column 1. Remaining columns are needed as it.

test data:

Code:
ProbeSet        GeneSymbol      X22565285     X22566285
ILMN_1050008    MYOCD   6.577   7.395
ILMN_1050014    GPRC6A  6.595   6.668
ILMN_1050017    FLJ38281        6.699   6.897
ILMN_1050019    LOC390084       7.41    7.839
ILMN_1050020    IMUP    6.777   7.74

Code:
awk '{printf $2"\t" ; for (i=2; i<=NF ;i++)  { print $i"\t"  } }'  file.txt

Bad output:

Code:
GeneSymbol      GeneSymbol
X22565285
X22566285
MYOCD   MYOCD
6.577
7.395
GPRC6A  GPRC6A
6.595
6.668
FLJ38281        FLJ38281
6.699
6.897
LOC390084       LOC390084
7.41
7.839
IMUP    IMUP
6.777
7.74

Rather I need output like:
Code:
GeneSymbol GeneSymbol X22565285 X22566285
MYOCD   MYOCD 6.577 7.395


Last edited by Scott; 12-06-2017 at 04:56 PM.. Reason: Replaced QUOTE tags with CODE tags
# 2  
Old 12-06-2017
Code:
$ awk '$1=$2'  file
GeneSymbol GeneSymbol X22565285 X22566285
MYOCD MYOCD 6.577 7.395
GPRC6A GPRC6A 6.595 6.668

or
Code:
$ awk '$1=$2' OFS="\t" file
GeneSymbol	GeneSymbol	X22565285	X22566285
MYOCD	MYOCD	6.577	7.395
GPRC6A	GPRC6A	6.595	6.668

# 3  
Old 12-06-2017
oh!

Thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need awk or Shell script to compare Column-1 of two different CSV files and print if column-1 matche

Example: I have files in below format file 1: zxc,133,joe@example.com cst,222,xyz@example1.com File 2 Contains: hxd hcd jws zxc cst File 1 has 50000 lines and file 2 has around 30000 lines : Expected Output has to be : hxd hcd jws (5 Replies)
Discussion started by: TestPractice
5 Replies

2. Shell Programming and Scripting

Print remaining lines using grep

Hi All, I am having a text file like below ERROR - Not a valid ID : 123 ERROR - Not a valid hello ID : 124 SUCCESS - Valid ID : 12 I need to display like below after reading the file if it finds the error keyword along with displaying this first line when error pattern... (10 Replies)
Discussion started by: rohit_shinez
10 Replies

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

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

awk command to print only selected rows in a particular column specified by column name

Dear All, I have a data file input.csv like below. (Only five column shown here for example.) Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 3,2,4,5,6 5,3,5,5,6 From this I want the below output Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 where the second column... (4 Replies)
Discussion started by: ks_reddy
4 Replies

6. Shell Programming and Scripting

duplicate elimination with column print

hi, my input a b c d e f g k i m g i k l b i n g o h m a b c d e b i n g o my output a b c d e f g k i m g i k l b i n g o h m what I would like to do is compare the first five columns of each row to the entire records in the file and if there is a match, eliminate that... (1 Reply)
Discussion started by: jacobs.smith
1 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. UNIX for Dummies Questions & Answers

print remaining part from the first-match within a file

Hi, i was looking for unix command(s) for : find the first occurrence of a given pattern with in a file and print the remaining part. below is an example of what i am looking for: lets say, a file named myfile.txt now, the command i am looking for will do the following (4 Replies)
Discussion started by: nurulamin862
4 Replies

10. Shell Programming and Scripting

print remaining file after a condition is satisfied

Hi , could any one suggest me that how to determine if the first field is numeric and if it is greater than another number then from that point everything else should be printed using awk. I have tried this : awk -v xxxx=$xxxxx ' BEGIN { enable=0 } { print $1 if ( ( $1 !~ "^*$" ... (5 Replies)
Discussion started by: hitmansilentass
5 Replies
Login or Register to Ask a Question