0

Sample of text:

ERROR IN CONNECTING TO NODE:**NT**SX01,CMS
ERROR IN CONNECTING TO NODE:**USSP**SX01,CMS
ERROR IN CONNECTING TO NODE:**PT**SX01,CMS

Want to grep the three lines in the same command.

grep "ERROR IN CONNECTING TO NODE:?SX01,CMS" 

What should I put in place of question mark so that all the three lines will grep?

  • Are there literal * characters in your input, or is that an attempt to highlight the text that you wish to match? – steeldriver Oct 6 '19 at 13:19
1

To match any characters .* betweeen NODE: and SX01,CMS, you can use

grep "^ERROR IN CONNECTING TO NODE:.*SX01,CMS$" file

The ^ matches the beginning of the line and $ matches the end of the line.

If you want to include the literal ** before and after NT, USSP and PT:

grep "^ERROR IN CONNECTING TO NODE:\*\*.*\*\*SX01,CMS$" file

If you want to include any letters between ** and **:

grep "^ERROR IN CONNECTING TO NODE:\*\*[A-Z]*\*\*SX01,CMS$" file

And to make it even more specific: grep for the strings NT or USSP or PT:

grep "^ERROR IN CONNECTING TO NODE:\*\*\(NT\|USSP\|PT\)\*\*SX01,CMS$" file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.