user2335924
user2335924

Reputation: 55

Removing strings from lines part of file in bash

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.

Upvotes: 0

Views: 124

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174844

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

Upvotes: 1

Related Questions