Execution problems using awk command.

Hi All,

I have the following requirement. In a directory i get files from external source. I at regular intervals check that directory for any incoming files.
The file name is underscore delimited.
Such as:

aaa_bbb_ccc_ddd_eee_fff.dat

I am using awk and and splitting the file name.

But now we are getting files with an extra parameter too.

aaa_bbb_ccc_ddd_eee_fff_ggg.dat

so there may be a combination of files with diferent field counts. So i am unable to parse the file name coz i dont know the exact field count as it may change for different file names :confused:.

I googled and i found out that optional parameters can be made use of in GAWK. But i need to know how to do it using awk. Any alternative apart from GAWK, awk(if not possible using awk) is also welcomed. Any help would be greatly appreciated.

You said:

I am using awk and and splitting the file name.

Post that code, not sure what your requirement is.

The code i am using for splitting filename using awk is :

awk -F "" ' {$1"_"$2"_"$3"_"$4"_"$5""$6} '

I need to incorporate for extra $7 if a file with 7 fields arrives.

Is this enough or did i miss any clarity? So problem occurs if in the directory both files with 6 and 7 fields exists.

Pls , Post exact input and the output your expecting .

Thanks friends. I got the solution.