After upgrading to RHEL8 or above, 'awk' command's 'OFS' variable behaves slightly differently from the one in RHEL7.

Solution Verified - Updated -

Issue

Let's assume we have a file as below.

$ cat test.txt
a, b, c, d, e, f, g
h, i, j, k, l, m, n
o, p, q, r, s, t, u

In RHEL7, I got the following result with awk command.

RHEL7 ~]$ cat test.txt | awk -F, '{$1=$1; OFS="*"; print $0}'
a* b* c* d* e* f* g
h* i* j* k* l* m* n
o* p* q* r* s* t* u

However, in RHEL8 or above, I got a different result with the same command.

RHEL8 ~]$ cat test.txt | awk -F, '{$1=$1; OFS="*"; print $0}'
a  b  c  d  e  f  g
h* i* j* k* l* m* n
o* p* q* r* s* t* u

Why does this difference occur?

Environment

  • Red Hat Enterprise Linux (RHEL) 8 and 9
  • gawk-4.2.1-1.el8 or above

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content