How to remove a value from first column in the second column?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to remove a value from first column in the second column?
# 1  
Old 10-09-2019
How to remove a value from first column in the second column?

HI,

I have a file like this:
Code:
5_2207830114	5_2207830114,13_2207830312,15_2207830336
8_2207830145	8_2207830145,15_2207830336
10_2207830220	5_2207830114,7_2207830138,8_2207830145,10_2207830220,12_2207830244,13_2207830312,15_2207830336,16_2207830343
12_2207830244	12_2207830244,15_2207830336,16_2207830343

I want an output like this:
Code:
5_2207830114	13_2207830312,15_2207830336
8_2207830145	15_2207830336
10_2207830220	5_2207830114,7_2207830138,8_2207830145,12_2207830244,13_2207830312,15_2207830336,16_2207830343
12_2207830244	15_2207830336,16_2207830343

SO basically I want to remove the value of the first column in the second column.

I tried several commands with awk but didn'T get the desired output. Can anyone help?

Thanks
# 2  
Old 10-09-2019
Can you post what you tried?
# 3  
Old 10-09-2019
I tried:
awk -F $'\t' '$1=/.*$2.*/ {print $0}' unique_matches.txt
but this does not result in anything...

and then I tried
Code:
awk -F $'\t' '$2=$1,/.*/ {print $0}' unique_matches.txt

but the output is:
Code:
5_2207830114 5_2207830114
8_2207830145 8_2207830145
10_2207830220 10_2207830220
12_2207830244 12_2207830244

so its somehow the opposite
# 4  
Old 10-09-2019
How about
Code:
awk '{sub ($1 ",", "", $2)} 1' file
5_2207830114 13_2207830312,15_2207830336
8_2207830145 15_2207830336
10_2207830220 5_2207830114,7_2207830138,8_2207830145,12_2207830244,13_2207830312,15_2207830336,16_22 07830343
12_2207830244 15_2207830336,16_2207830343

This User Gave Thanks to RudiC For This Post:
# 5  
Old 10-09-2019
Wow, thank you, that's perfect!...and actually so simple :-D
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove the values from a certain column without deleting the Column name in a .CSV file

(14 Replies)
Discussion started by: dhruuv369
14 Replies

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

3. Shell Programming and Scripting

Remove the first character from the fourth column only if the column has four characters

I have a file as follows ATOM 5181 N AMET K 406 12.440 6.552 25.691 0.50 7.37 N ATOM 5182 CA AMET K 406 13.685 5.798 25.578 0.50 5.87 C ATOM 5183 C AMET K 406 14.045 5.179 26.909 0.50 5.07 C ATOM 5184 O MET K... (14 Replies)
Discussion started by: hasanabdulla
14 Replies

4. Shell Programming and Scripting

Difference of the same column when two other column matches and one column differs less than 1 hour

This is my input file : # cat list 20130430121600, cucm, location,76,2 20130430121600,cucm1,location1,76,4 20130430122000,cucm,location,80,8 20130430122000,cucm1,location1,90,8 20130430140000,cucm1,location1,87,11 20130430140000, cucm,location,67,9 This is the required output ... (1 Reply)
Discussion started by: Lakshmikumari
1 Replies

5. Shell Programming and Scripting

remove brackets and put it in a column and remove repeated entry

Hi all, I want to remove the remove bracket sign ( ) and put in the separate column I also want to remove the repeated entry like in first row in below input (PA156) is repeated ESR1 (PA156) leflunomide (PA450192) (PA156) leflunomide (PA450192) CHST3 (PA26503) docetaxel... (2 Replies)
Discussion started by: manigrover
2 Replies

6. Shell Programming and Scripting

Rename a header column by adding another column entry to the header column name URGENT!!

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (4 Replies)
Discussion started by: Vavad
4 Replies

7. Shell Programming and Scripting

need to remove duplicates based on key in first column and pattern in last column

Given a file such as this I need to remove the duplicates. 00060011 PAUL BOWSTEIN ad_waq3_921_20100826_010517.txt 00060011 PAUL BOWSTEIN ad_waq3_921_20100827_010528.txt 0624-01 RUT CORPORATION ad_sade3_10_20100827_010528.txt 0624-01 RUT CORPORATION ... (13 Replies)
Discussion started by: script_op2a
13 Replies

8. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
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
Login or Register to Ask a Question