user2108144
user2108144

Reputation: 3

print out found result of regexp in RS

Hi all can you help me print out result of regexp in RS ?

awk 'BEGIN {RS="--[0-9a-zA-Z]+--"} /pattern/' awk-test.txt

pattern="--[0-9a-zA-Z]+--" can be equal --95700e1b-- or --0dcaf754-- or else awk print out block of text between RS, how can I print found RS too?

PS sorry for my bad English.

Upvotes: 0

Views: 70

Answers (1)

William Pursell
William Pursell

Reputation: 212464

Since RS can only be a single character in a portable awk script, I'll assume you are using gawk. In that case, you can reference RT, which will contain the text that matched the regular expression specified in RS. (RT is the record terminator, so it is the value of the text that matches RS at the end of the current record rather than the beginning.)

Upvotes: 1

Related Questions