I want to grep a file that stops at the first match, example:
${A57}${A17}${A23}${A20}${A35}${A57}${A33}${A24}${A38}${A38}${A24}${A17}${A57}${A33}${A23}${A38}${A18}${E52}${A28}${A28}${A28}${A25}${A38}${A22}${A50}${A30}${A57}${A37}${A18}${A44}${A15}${A28}${A29}${A29}${A29}${A29}${A14} When I use grep -o "${A57}.\*${A29}${A14}" I obtain this output:
${A57}${A17}${A23}${A20}${A35}${A57}${A33}${A24}${A38}${A38}${A24}${A17}${A57}${A33}${A23}${A38}${A18}${E52}${A28}${A28}${A28}${A25}${A38}${A22}${A50}${A30}${A57}${A37}${A18}${A44}${A15}${A28}${A29}${A29}${A29}${A29}${A14} Now my question is how can I stop grep with the first match of '${A57}' so that I have this output:
${A57}${A37}${A18}${A44}${A15}${A28}${A29}${A29}${A29}${A29}${A14}
.*to not retrieve the longest possible match; that's what*means. Some regular expression tools likegrep -P(if you have that) allow for non-greedy matching with.*?${A57}in the match..*one way or another. Given that we have to guess what these variables contain, there is really no good way to answer it without speculation. Perhaps the OP will want to edit to clarify what behavior exactly they are looking for, if indeed they don't think that the many answers to the duplicate solve their problem.$s.