Help to understand this awk command

November 13, 2020 at 05:59:55
Specs: Red Hat Enterprise 7, T5240
Hi Guys,

Yesterday i was looking sor a solution to sort part of a file and i came across with this AWK solution that worked perfectly:

awk 'i {a[l++]=$0}
     /^\(/ {print; i=1}
     /^\)/ {n=asort(a); for(k=1; k<=n; k++){print a[k]} i=0; delete a; next}
     !i' File

I would like to understand why he put the variable "i" in begin and at the end of AWK,

I really didnt undertsand how it works.
If anyone have some internet page that explain this, i can read.

Just to clarify, this solution is to sort the text bellow, between the "(" and ")":

CREATE TABLE BBBBBB
(
   ID bigint NOT NULL
   NAME varchar(50)
   CURRENCY varchar(3)
   SYS_START timestamp NOT NULL
   SYS_END timestamp NOT NULL
   TS_ID timestamp NOT NULL
   EXPORT int
)

CREATE TABLE AA
(
   ID bigint NOT NULL
   SYS_START timestamp NOT NULL
   SYS_END timestamp NOT NULL
   TS_ID timestamp NOT NULL
   NAME varchar(100) NOT NULL
)

message edited by surfistadesampa


See More: Help to understand this awk command

Related Solutions


Ask Question