Reputation:
Using Awk I want to match the entire record using a regular expression. By default the regular expression matching is for parts of a record.
The ideal solution would:
However any and all solutions are of interest as long as they use Awk without calls to external programs.
An example, I have:
$ ls
indata.txt t1.awk
$ cat indata.txt
a1010_
1010_
1010_b
$ cat t1.awk
/[01]*_[01]*/ { print $0 }
I get:
$ awk -f t1.awk indata.txt
a1010_
1010_
1010_b
This is the result I am seeking:
$ awk -f t1.awk indata.txt
1010_
Upvotes: 1
Views: 1249
Reputation: 182782
You just need to add a beginning and end anchor to your regex:
/^[01]*_[01]*$/ { print $0 }
Upvotes: 4