2. Sample Files
Let me show you some sample file that I am going to use in this post to show you how you are going to use awk.
Let’s get the famous table data into file: EMP and DEPT table. I created the files in csv format.
EMP.csv –
EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO
7839,KING,PRESIDENT,,11/17/1981,5000,,10
7698,BLAKE,MANAGER,7839,05/01/1981,2850,,30
7782,CLARK,MANAGER,7839,06/09/1981,2450,,10
7566,JONES,MANAGER,7839,04/02/1981,2975,,20
7788,SCOTT,ANALYST,7566,12/09/1982,3000,,20
7902,FORD,ANALYST,7566,12/03/1981,3000,,20
7369,SMITH,CLERK,7902,12/17/1980,800,,20
7499,ALLEN,SALESMAN,7698,02/20/1981,1600,300,30
7521,WARD,SALESMAN,7698,02/22/1981,1250,500,30
7654,MARTIN,SALESMAN,7698,09/28/1981,1250,1400,30
7844,TURNER,SALESMAN,7698,09/08/1981,1500,0,30
7876,ADAMS,CLERK,7788,01/12/1983,1100,,20
7900,JAMES,CLERK,7698,12/03/1981,950,,30
7934,MILLER,CLERK,7782,01/23/1982,1300,,10
DEPT.csv –
DEPTNO,DNAME,LOC
10,ACCOUNTING,NEW YORK
20,RESEARCH,DALLAS
30,SALES,CHICAGO
40,OPERATIONS,BOSTON
You can download above files using below link:
Let’s do most simplest operation like select * from table to verify the content:
$ column -nts, EMP.csv
$ column -nts, DEPT.csv
Now let’s begin SQL vs AWK. Read on page 3..
Great content. This help alot. Thank you so much.
No problem. Thanks to you too for going through the content.
What a great content 🙂
Thanks
Thanks Jessica !! It means a lot. 🙂
The problem is that awk is NOT a CSV parser.
I.e. with the , separator, if we have a field value of “SURNAME,NAME” in this case the AWK threats it as two different fields.
Use goawk instead.
Yes. Good point. If the delimiter is part of the column value itself, then awk will fail to operate. We always encourage to use character like pipe or something else as delimiter which doesn’t present in the data. GoAWK is good solution for this. But yet to available as part of distributions.