I've got problem with removing part of string between two patterns with sed. I've always got last PATTERN-2 in line:
PATTERN-1xxxxPATTERN-2aaa PATTERN-1xxxxPATTERN-2fffPATTERN-1zzzzPATTERN-2gggPATTERN-1zzzzPATTERN-2 PATTERN-1xxxxPATTERN-2bbb
sed 's/PATTERN-1.*PATTERN-2//g' test.txt
the result of above is
but I would like to have
aaa fffggg bbb
Is possible to find PATTERN-2 which is closest to PATTERN-1?