Column as File Name

Hi ,

Can any one suggest me how to proceed for achieving the below target data.

source data

File_name|EMPNO|sal|DEPTNO|ABC|XYZ
emp.txt|123|2000|02| | 
dept.txt| | | 03| | |
emp.txt|432|1421|03|
sal.txt| | | |123| 127

Based on my first column, I need to create .txt file for each entity type..so here I have to create 3 .txt files as below

file name -- emp.txt
file data

EMPNO|sal|DEPTNO|ABC|XYZ
23|2000|02| | 
432|1421|03|
file name -- dept.txt
file data

EMPNO|sal|DEPTNO|ABC|XYZ
dept.txt| | | 03| | |
file name -- sal.txt
 file data

EMPNO|sal|DEPTNO|ABC|XYZ
  | | |123| 127

can you suggest me a logic for acheving the same.

Thx,wang

can u post wat you have tried !!!! and we can help you to proceed further

 
awk -F"|" 'NR > 1 {f=$1;$1="";a[f]=$0;print a[f] >> f }' OFS="|" input_file

populating the headings in each file is left to you to understand how it works!!

Regards
Ravi