I want to grep lines starting with a @ and also lines starting with // followed by a line starting with @
Example:
//text1
@text2
text3
result:
//text1
@text2
How can I do this with grep or any other basic unix tool?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This one-liner processes STDIN one line at a time.
If a line beginning with
@is found it dumps the contents of$zfollowed by the current line.Then, if it detects a line beginning with
//it saves the line in a variable$z. The$zvariable is cleared if the line does not start with//.I have given this a quick test and should do the job requested.
The
greptool does not remember state between lines.