How to replace part of header, remove between two characters bash, awk, sed How to replace part of header, remove between two characters bash, awk, sed unix unix

How to replace part of header, remove between two characters bash, awk, sed


Using gnu sed you can use a negated bracket expression:

sed 's/_[^\t]*//g' file

_[^\t]* matches underscore followed by zero or more non-tab characters.


try in awk:

awk '{gsub(/_[^\\]*/,"");print}'   Input_file

try in sed:

sed 's/_[^\\]*//g'   Input_file

EDIT: As OP said \t are the TABs in Input_file so adding following solution too now.

awk '{gsub(/_[^\t]*/,"");print}'  Input_file


sed 's/_[^\t]*\t/\t/g'

if you're not worried about the last field.

sed 's/_[^\t]*\t/\t/g;s/_[^\t]*$//'

otherwise.