# Execution problems using awk command.

**URL:** <https://community.unix.com/t/execution-problems-using-awk-command/246737>\
**Category:** Shell Programming and Scripting\
**Created:** [August 10, 2009, 11:05pm UTC](https://community.unix.com/t/execution-problems-using-awk-command/246737 "2009-08-10T23:05:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![satishpv\_2002](https://community.unix.com/letter_avatar/satishpv_2002/32/6_449c533f586939b6e5f246632a46421f.png) [@satishpv\_2002](https://community.unix.com/u/satishpv_2002)\
**Post date:** [August 10, 2009, 11:05pm UTC](https://community.unix.com/t/execution-problems-using-awk-command/246737/1 "2009-08-10T23:05:59Z")

</div>

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 😕.

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.

---

<div class="post-metadata">

**Author:** ![edidataguy](https://community.unix.com/letter_avatar/edidataguy/32/6_449c533f586939b6e5f246632a46421f.png) [@edidataguy](https://community.unix.com/u/edidataguy)\
**Post date:** [August 11, 2009, 12:39am UTC](https://community.unix.com/t/execution-problems-using-awk-command/246737/2 "2009-08-11T00:39:48Z")

</div>

You said:

```auto
I am using awk and and splitting the file name.

```

Post that code, not sure what your requirement is.

---

<div class="post-metadata">

**Author:** ![satishpv\_2002](https://community.unix.com/letter_avatar/satishpv_2002/32/6_449c533f586939b6e5f246632a46421f.png) [@satishpv\_2002](https://community.unix.com/u/satishpv_2002)\
**Post date:** [August 11, 2009, 1:30am UTC](https://community.unix.com/t/execution-problems-using-awk-command/246737/3 "2009-08-11T01:30:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![panyam](https://community.unix.com/letter_avatar/panyam/32/6_449c533f586939b6e5f246632a46421f.png) [@panyam](https://community.unix.com/u/panyam)\
**Post date:** [August 11, 2009, 3:04am UTC](https://community.unix.com/t/execution-problems-using-awk-command/246737/4 "2009-08-11T03:04:18Z")

</div>

Pls , Post exact input and the output your expecting .

---

<div class="post-metadata">

**Author:** ![satishpv\_2002](https://community.unix.com/letter_avatar/satishpv_2002/32/6_449c533f586939b6e5f246632a46421f.png) [@satishpv\_2002](https://community.unix.com/u/satishpv_2002)\
**Post date:** [August 16, 2009, 10:17pm UTC](https://community.unix.com/t/execution-problems-using-awk-command/246737/5 "2009-08-16T22:17:25Z")

</div>

Thanks friends. I got the solution.
