remove characters from string based on occurrence of a string

Hello Folks..

I need your help ..

here the example of my problem..i know its easy..i don't all the commands in unix to do this especiallly sed...here my string..

dwc2_dfg_ajja_dfhhj_vw_dec2_dfgh_dwq

desired output is..

dwc2_dfg_ajja_dfhhj

it's a simple task with tail command, but my string size varies..only constant thing is ocuurance of this string "_vw_"

I greatly appretiate your help..

Thanks

try:

sed 's/\(.*\)\(_vw_.*\)/\1/' urfile
1 Like

Hello yinyuemi,

what's the command would be to get string after ocuurance of string "_vw_"

Thanks for your reply

sed 's/\(.*_vw_\)\(.*\)/\2/' urfile
1 Like

Thanks Yinyuemi..

I greatly apperitiate you help

$ var=dwc2_dfg_ajja_dfhhj_vw_dec2_dfgh_dwq
$ echo ${var%%_vw_*}
dwc2_dfg_ajja_dfhhj