0

I have a file with below text

^[[8mha:AAAAYB+LCAAAAAAAAP9b85aBtbiIQSmjNKU4P0+vJLE4u1gvPjexLDVPzxdEuhYV5Rf55ZekOlc7RKnPKH7IxMBQUcQgBdWQnJ9XnJ+TqucMoUEKGSCAEaSwAACsNFCqYAAAAA==^[[0m[ERROR] ^[[8mha:AAAAYB+LCAAAAAAAAP9b85aBtbiIQSmjNKU4P0+vJLE4u1gvPjexLDVPzxdEuhYV5Rf55ZekOlc7RKnPKH7IxMBQUcQgBdWQnJ9XnJ+TqucMoUEKGSCAEaSwAACsNFCqYAAAAA==^[[0m[ERROR] /opt/app/ElectronicTransactionVOtoDOMapper.java:[1060,1] error: reached end of file while parsing ^[[8mha:AAAAYB+LCAAAAAAAAP9b85aBtbiIQSmjNKU4P0+vJLE4u1gvPjexLDVPzxdEuhYV5Rf55ZekOlc7RKnPKH7IxMBQUcQgBdWQnJ9XnJ+TqucMoUEKGSCAEaSwAACsNFCqYAAAAA==^[[0m[ERROR] -> [Help 1] ^[[8mha:AAAAYB+LCAAAAAAAAP9b85aBtbiIQSmjNKU4P0+vJLE4u1gvPjexLDVPzxdEuhYV5Rf55ZekOlc7RKnPKH7IxMBQUcQgBdWQnJ9XnJ+TqucMoUEKGSCAEaSwAACsNFCqYAAAAA==^[[0m[ERROR] ^[[8mha:AAAAYB+LCAAAAAAAAP9b85aBtbiIQSmjNKU4P0+vJLE4u1gvPjexLDVPzxdEuhYV5Rf55ZekOlc7RKnPKH7IxMBQUcQgBdWQnJ9XnJ+TqucMoUEKGSCAEaSwAACsNFCqYAAAAA==^[[0m[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch

from the above log, I have to extract only the below:

[ERROR]
[ERROR] /opt/app/ElectronicTransactionVOtoDOMapper.java:[1060,1] error: reached end of file while parsing
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch

Eventually, I should not get the Junk value in the log instead I need a clear Error message.

Could you please help me in getting the right command in shell?

2
  • 3
    Please show your coding efforts. Commented Oct 29, 2016 at 8:06
  • I derived this.. cat -v log_10-29-2016_04_12 | grep -o '[ERROR.*' but not sure that the command works in all scenarios. Commented Oct 29, 2016 at 8:15

3 Answers 3

1

probably should use sed rather than grep here.

sed -n '/ERROR/s/.*\(\[ERROR\].*\)$/\1/p' log_10-29-2016_04_12

gets only lines containing the word 'ERROR' and strips everything from the left of the '[ERROR]' and prints the rest.

Sign up to request clarification or add additional context in comments.

Comments

0
awk -vRS='^' -F "] " '/ERROR/{print "[ERROR] "$2}' file

1 Comment

While this code snippet may solve the problem, it doesn't explain why or how it answers the question. Please include an explanation for your code, as that really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Flaggers / reviewers: For code-only answers such as this one, downvote, don't delete!
0

Try below grep command to achieve the output -

vipin@kali:~$ grep "\[ERROR\]" kk.txt |cut -c6-
[ERROR]
[ERROR] /opt/app/ElectronicTransactionVOtoDOMapper.java:[1060,1] error: reached end of file while parsing
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch

explanation : \[ and \] for escaping and -c6- to print after 6th character till end of line.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.