how to change the current file processing to some other random file in awk ?

Hello,
say suppose i am processing an file emp.dat the field of which are
deptno empno empname etc
now say suppose i want to change the file to emp.lst then how can i do it? Here i what i attempted but in vain

BEGIN{
	system("sort emp.dat > emp.lst") 
	FILENAME="emp.lst"
}
{
	print ($0)
}

i run the script file as

 awk -f main.awk emp.dat

Thanks in advance! :slight_smile:

Use a shell script wrapper to sort the file, and call awk with the sorted file, or pipe the output of sort to awk:

sort emp.dat | awk ' ... '

thanks cfajohnson :slight_smile:
you solved my problem.