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

2 Answers 2

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

1
  • Thank you! This works in my case. Commented Jul 30, 2019 at 16:32
1

Done by below awk command

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

output

TEST 1
TEST 2
TEST 3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .