AishwaryaKulkarni AishwaryaKulkarni - 4 months ago 13
Bash Question

Deleting everything in a single column after a certain pattern

I have following lines

ABC-Dup2 XUAS BSNMM
CVD nbvn nbmsb
SVDB-Dup4 NBV KJHA
TTS-Dup7 MNMN NBA


I want to remove -Dup from the FIRST COLUMN ONLY and retain rest of the columns such that I have

ABC XUAS BSNMM
CVD nbvn nbmsb
SVDB NBV KJHA
TTS MNMN NBA


I am trying sed 's/-Dup.*//1' but it's removing the rest of the columns from that row too.

Answer

If the pattern is -Dup followed by a number then you could try something like

sed 's/-Dup[0-9]*//1'