0

I have the following lines in a log file:

<ROW USER_GID="TEST 1" FLOW="Norm" SEQUENCE="9"/>
<ROW USER_GID="TEST 2" FLOW="Norm" SEQUENCE="2"/>
<ROW USER_GID="TEST 3" FLOW="Norm" SEQUENCE="2"/>

I am trying to extract the value of USER_GID in each line. Can I accomplish the same using grep/awk or sed command.

In the above case the output should return:

TEST 1 
TEST 2
TEST 3
1

While you can perform this operation via sed, you might be better off using an XML parser to get the right lines for you.

That said, you can use the following sed command, assuming all your data is in the same format.

sed -n 's/.*USER_GID="\([^"]*\)".*/\1/p' log_file

  • Thank you! This works in my case. – GameShark94 Jul 30 at 16:32
1

Done by below awk command

awk -F '"' '/USER_GID/{print $2}' filename

output

TEST 1
TEST 2
TEST 3

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.