Radoslav Todorov
Radoslav Todorov

Reputation: 133

How to use the built-in variables FS an RS in awk?

This is the content of a file i am working with.

<Overall>1
<Value>2
<Rooms>3
<Location>4

<Overall>5
<Value>6
<Rooms>7
<Location>8

My attempt was

 awk ' BEGIN{ FS="<.*>"; RS=""; } { print $2 } ' $1

Desired output

1
5

Actual output

4
8

Could someone point out what where mistake is?

Upvotes: 2

Views: 342

Answers (1)

P....
P....

Reputation: 18411

awk ' BEGIN{ FS="<[^>]+>"; RS=""; } { print $2 } ' inputfile

Modify the FS value to FS="<[^>]+>" . Or as suggested by Inian , Go for defining field contents using FPAT.

<[^>]+> Means, < followed by anything(one or more) which is not equal to > till >.

Upvotes: 2

Related Questions