0

I need to remove/be rid of string as follow par of one file:

Here is my line:

2014-08-05T13:16:29+01:00 (INFO:3824.87075728): [27219] [ <[email protected]>] A message from <[email protected]> source]

As a result, I am trying to get like:

2014-08-05T13:16:29+01:00 (INFO:3824.87075728): [27219] source

In fact its to rid of the email addresses.

Thank you all for all your suggestions.

AL

I have tried to following using sed:

sed -e 's/<.* from//g'

2014-08-05T13:16:29+01:00 (INFO:3824.104725392): [27219] [  <[email protected]> source

As now, I am trying to figure how could I remove from [ until source.

Thank you.

3
  • use s command of sed. The pattern depends on exact content you wish to remove, but as the first step you may wish to remove email-s. The basic command is sed -e "s/${EMAIL_PATTERN}//g". The exact value of ${EMAIL_PATTERN} depends on your accuracy, the official pattern is here It's a bit lengthy :) Commented Aug 6, 2014 at 9:26
  • But the source was present within the ] bracket. If you want to get rid off email address then why the string A message from is removed? Commented Aug 6, 2014 at 9:26
  • Ah, that's not a problem. Just escape all "bad symbols". For example sed -e 's,\(\[\|\]\),,g;' removes all brackets from the string. Commented Aug 6, 2014 at 9:37

1 Answer 1

1

The below awk command would print the first three columns and the last column with ] symbol removed.

$ echo '2014-08-05T13:16:29+01:00 (INFO:3824.87075728): [27219] [ <[email protected]>] A message from <[email protected]> source]' | awk '{gsub(/]/,"",$NF); print $1,$2,$3,$NF}'
2014-08-05T13:16:29+01:00 (INFO:3824.87075728): [27219] source

OR

$ echo '2014-08-05T13:16:29+01:00 (INFO:3824.87075728): [27219] [ <[email protected]>] A message from <[email protected]> source]' | sed 's/\[ .*\(source\).*$/\1/g'
2014-08-05T13:16:29+01:00 (INFO:3824.87075728): [27219] source
Sign up to request clarification or add additional context in comments.

3 Comments

Hi thanks, ideally I was willing to use sed; as sometime the initial line might vary.
please answer this so that we could understand what you are trying to do.
The pb, is that sometime after source, line might vary so using awk would avoid to see what is included.

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.