# problem with awk command in script.

**URL:** <https://community.unix.com/t/problem-with-awk-command-in-script/272630>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [September 2, 2010, 2:07am UTC](https://community.unix.com/t/problem-with-awk-command-in-script/272630 "2010-09-02T02:07:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![shrima.pratima](https://community.unix.com/letter_avatar/shrima.pratima/32/6_22734026db12803ebb3e059622ac3534.png) [@shrima.pratima](https://community.unix.com/u/shrima.pratima)\
**Post date:** [September 2, 2010, 2:07am UTC](https://community.unix.com/t/problem-with-awk-command-in-script/272630/1 "2010-09-02T02:07:08Z")

</div>

```nohighlight
#!/bin/sh
date=`date +%y%m%d -d"1 day ago"`
inbound_dir=/vis/logfiles/to_solmis
            cp `grep -il ST~856~ $inbound_dir/*$date*` /vis/sumit/in_ASN/
            echo 'SENDER,RECEIVER,DATE,TIME,ASNUMBER' > a.csv
            for i in /vis/sumit/in_ASN/*
            do
                 mkdir -p /vis/sumit/inboundasns.$date
                 cp `echo $i` /vis/sumit/inboundasns.$date 
                 tr -c '[A-Z] [0-9] [a-z] ~' '[*]' <$i > b
                 awk -F "DTM~" '{print $1}' b > c
                 awk -F "~SH~" '{print $2}' c > d
                 awk -F "~" '{print $1","$2","$3","$4","$11}' d >> a.csv
            done

```

Please suggest how to read or print a file which is of 3000 bytes using awk command..  
Error is awk cannot read a file whose length is greater than 3000.  
Any alternative ????

---

<div class="post-metadata">

**Author:** ![john1212](https://community.unix.com/letter_avatar/john1212/32/6_22734026db12803ebb3e059622ac3534.png) [@john1212](https://community.unix.com/u/john1212)\
**Post date:** [September 2, 2010, 3:33pm UTC](https://community.unix.com/t/problem-with-awk-command-in-script/272630/2 "2010-09-02T15:33:28Z")

</div>

> [@shrima.pratima](#):
>
> Please suggest how to read or print a file which is of 3000 bytes using awk command..  
> Error is awk cannot read a file whose length is greater than 3000

Are you sure?  
try:

```plaintext
cat very_long_file.txt
awk very_long_file.txt

```

any errors, print it  
What's your OS? What's version?

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_22734026db12803ebb3e059622ac3534.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [September 2, 2010, 4:57pm UTC](https://community.unix.com/t/problem-with-awk-command-in-script/272630/3 "2010-09-02T16:57:48Z")

</div>

> [@john1212](#):
>
> Are you sure?

I believe he means lines, not files. Many versions do have an arbitrary limit on the length of lines.

If it's available on your system, try nawk instead of awk. That should be GNU awk, which doesn't have a limit that I'm aware of.

---

<div class="post-metadata">

**Author:** ![Scott](https://community.unix.com/letter_avatar/scott/32/6_22734026db12803ebb3e059622ac3534.png) [@Scott](https://community.unix.com/u/Scott)\
**Post date:** [September 2, 2010, 4:58pm UTC](https://community.unix.com/t/problem-with-awk-command-in-script/272630/4 "2010-09-02T16:58:58Z")

</div>

> [@john1212](#):
>
> Are you sure?  
> try:
> 
> ```plaintext
> cat very_long_file.txt
> awk very_long_file.txt
> 
> ```
> 
> any errors, print it  
> What's your OS? What's version?

Older awk's more than likely have such a limit. awk on Solaris, for example has a limit of 2.5K-1 byte line length.

Newer awk's most likely don't have such limitations.

---

<div class="post-metadata">

**Author:** ![john1212](https://community.unix.com/letter_avatar/john1212/32/6_22734026db12803ebb3e059622ac3534.png) [@john1212](https://community.unix.com/u/john1212)\
**Post date:** [September 3, 2010, 1:05am UTC](https://community.unix.com/t/problem-with-awk-command-in-script/272630/5 "2010-09-03T01:05:39Z")

</div>

This is the difference.  
There is no limit of file size.  
There's a limit of record lenght.  
Use nawk, gawk.  
GNU awk is gawk. It's for many distributions.

---

<div class="post-metadata">

**Author:** ![shrima.pratima](https://community.unix.com/letter_avatar/shrima.pratima/32/6_22734026db12803ebb3e059622ac3534.png) [@shrima.pratima](https://community.unix.com/u/shrima.pratima)\
**Post date:** [September 3, 2010, 2:16am UTC](https://community.unix.com/t/problem-with-awk-command-in-script/272630/6 "2010-09-03T02:16:55Z")

</div>

Hi all,

Thanks for your reply.

I entered nawk instead of awk but didnt work.  
error is: nawk not found.  
My OS HP-UX.  
my script is not able read the file and pick up the required fields when the total size of record was greater than 3000 bytes.

Error looks like:  
awk: Input line ISA~00~ ~00 cannot be longer than 3,000 bytes.  
The source line number is 1.

How to overcome this error??

---

<div class="post-metadata">

**Author:** ![john1212](https://community.unix.com/letter_avatar/john1212/32/6_22734026db12803ebb3e059622ac3534.png) [@john1212](https://community.unix.com/u/john1212)\
**Post date:** [September 3, 2010, 3:33am UTC](https://community.unix.com/t/problem-with-awk-command-in-script/272630/7 "2010-09-03T03:33:58Z")

</div>

Is this a joke?  
This is very funny.

```nohighlight
tr -c '[A-Z] [0-9] [a-z] ~' '[*]' <$i > b

```

you translate all characters A..Z, 0..9, a..z, ~ to ' ',  
now you set FS-field separator to 'DTM~' (no any characters D, T, M, ~) what for

```nohighlight
awk -F "DTM~" '{print $1}' b > c

```

.......

---

<div class="post-metadata">

**Author:** ![shrima.pratima](https://community.unix.com/letter_avatar/shrima.pratima/32/6_22734026db12803ebb3e059622ac3534.png) [@shrima.pratima](https://community.unix.com/u/shrima.pratima)\
**Post date:** [September 3, 2010, 3:58am UTC](https://community.unix.com/t/problem-with-awk-command-in-script/272630/8 "2010-09-03T03:58:15Z")

</div>

actually sample of data look like:

```nohighlight
ISA~00~ ~00~ ~ZZ~ABCDE ~ZZ~AAAAA ~100902~0647~U~00200~000003479~0~P~>
GS~SH~ABCDE~0185A~100902~0647~2173~X~002002XXX
ST~856~0001BSN~00~00902064701~100902~0647
DTM~011~100902~1014

```

Every file contain such type of data varying in record length.  
I need to read all records & pick up fields from the record that are in red and store it .csv file.

For this I wrote a script.  
I am beginner,I dont know how to use FS in awk command.

Advise me sir...

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_22734026db12803ebb3e059622ac3534.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [September 3, 2010, 11:11am UTC](https://community.unix.com/t/problem-with-awk-command-in-script/272630/9 "2010-09-03T11:11:37Z")

</div>

> [@shrima.pratima](#):
>
> Hi all,
> 
> Thanks for your reply.
> 
> I entered nawk instead of awk but didnt work.  
> error is: nawk not found.

Try gawk instead, then.

And if you don't have either, install one.
