1

I've got a file which contains lot of strings like below input. Need to extract the below output and process it further.

Input:

History={ExecAt=[2013-05-03 03:00:20,2013-05-03 03:00:23,2013-05-03 03:00:26],MId=["msgId3","msgId4","msgId5"]};

Output should be:

MId=["msgId3","msgId4","msgId5"]

using (sed 's/^.*,MId=/MId/') command i got the output like MId=["msgId3","msgId4","msgId5"]}; but still wanted the exact output (need to remove last 2 special chars }; here).

2 Answers 2

1

This works for me:

sed 's/.*\(MId=.*\)\}.*/\1/'
Sign up to request clarification or add additional context in comments.

Comments

1

If your grep supports the -o option, you can use it rather than sed:

grep -o 'MId=\[[^]]\+\]'

Using the same regex in sed works fine, just remove anything before and after:

sed -e 's/.*\(MId=\[[^]]\+\]\).*/\1/'

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.