Delete string between 3rd tab and first pattern with SED

Hello,

I have this sentence :

Pattern1        Pattern2       Pattern3       Pattern4-which-contains-HELLO-string-and-other-stuff-and-second-HELLO-and-third-HELLO

I want to delete everything between the 3rd tab (\t) and the FIRST pattern "HELLO" of the line.

Result expected is :

Pattern1       Pattern2       Pattern3       -string-and-other-stuff-and-second-HELLO-and-third-HELLO

I've this command

sed 's/\(.*\)\t.*HELLO\(.*\)/\1 \2/'

But it delete only after 2nd \t and not 3rd, and it ends at the LAST "HELLO" and not FIRST.

Can you help me ?

If your input text does not contain greater/lessthan symbols, then this will work:
It also depends on the fact that there are not any tabs after the third one.

sed 's/.*\t/&</; s/HELLO/&>/; s/<.*>//'

It adds "<" after the last tab and ">" after the first hello, then deletes everything between.

Hi,

It doesn't work. It give me

pattern1       pattern2       pattern3      Pattern4-which-contains-HELLO>-string-and-other-stuff-and-second-HELLO-and-third-HELLO <

Is there a way to specify 3rd tab as 1st pattern and 1st HELLO as 2nd pattern and replace everything by nothing between these two patterns ?

Those might not be tabs in your input, but a string of 8 blanks. Does this work:

sed 's/.*        /&</; s/HELLO/&>/; s/<.*>//'

Hi,

Yes it is, I cannot paste it between code tags on the forum.

Right -- I initially ran into that when pasting your example into a file to test locally; had to convert them to tabs.

Ok, it might be that '\t' isn't recognised by your awk as TAB. Try running the original sed, but instad of using '\t' actually type a TAB there. If that doesn't do it, I'm not sure what is going on.

Try:

perl -pe 's/[^\t]*?HELLO//' 

-or-

sed 's/[^\t]*HELLO\([^\t]*HELLO[^\t]*HELLO\)/\1/'

Hello, is it possible to do with sed ? Because it comes from a stream (tshark) and I have already a pipe with some sed cmds. If I do another pipe, it will create a buffer.

---------- Post updated at 01:01 PM ---------- Previous update was at 12:47 PM ----------

Wonderful I love you