[Solved] Extract First character in fourth column

Hi Experts,

I am new to UNIX. One of my file records are like below

220 IN C/A 515013 NULL NULL 
220 IN C/A 515017 NULL NULL
225 IN C/A 333701 NULL NULL
225 IN C/A 515034 NULL NULL
225 IN C/A 499201 NULL NULL
225 IN C/A 499202 NULL NULL

The above mentioned records delimiter is space. I need to extract the records from the 4th column where if any record prefix with 5, then I need to extract the entire records from that file. Please guide me how can I extract the prefix '5' from the 4th column.

Any help is really appreciated.

Expected output:

220 IN C/A 515013 NULL NULL 
220 IN C/A 515017 NULL NULL
225 IN C/A 515034 NULL NULL

What have you tried so far?

Thanks for your reply.

I have tried like below. But I did not get any result.

awk -F' ' $4='^5' file.txt

Please guide me how to handle this issue

Use regexp comparison operator:

awk '$4~/^5/' file

Thanks Yoda! for your help at the right time.

I got my expected result.

Thanks once again :slight_smile: