# awk syntax error

**URL:** <https://community.unix.com/t/awk-syntax-error/154027>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [June 14, 2005, 11:41am UTC](https://community.unix.com/t/awk-syntax-error/154027 "2005-06-14T11:41:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![k11](https://community.unix.com/letter_avatar/k11/32/6_449c533f586939b6e5f246632a46421f.png) [@k11](https://community.unix.com/u/k11)\
**Post date:** [June 14, 2005, 11:41am UTC](https://community.unix.com/t/awk-syntax-error/154027/1 "2005-06-14T11:41:29Z")

</div>

can anyone see the awk syntax error near line 1? I keep getting this error and I'm not familiar with awk very well yet so it is hard for me to see the errors.  
fyi: deleteuser\* refers to files in the directory where each one ends with a different date

ls -1 /mfupload/prod02/ftp/deleteuser\* | while read line  
do  
cat $line | awk -F '|' {printf "%s|%\n", $5, $3} \>\> ftp.dat  
done

---

<div class="post-metadata">

**Author:** ![bhargav](https://community.unix.com/user_avatar/community.unix.com/bhargav/32/130_2.png) [@bhargav](https://community.unix.com/u/bhargav)\
**Post date:** [June 14, 2005, 11:46am UTC](https://community.unix.com/t/awk-syntax-error/154027/2 "2005-06-14T11:46:01Z")

</div>

cat $line

replace it by

echo $line

---

<div class="post-metadata">

**Author:** ![Just\_Ice](https://community.unix.com/user_avatar/community.unix.com/just_ice/32/165_2.png) [@Just\_Ice](https://community.unix.com/u/Just_Ice)\
**Post date:** [June 14, 2005, 11:52am UTC](https://community.unix.com/t/awk-syntax-error/154027/3 "2005-06-14T11:52:49Z")

</div>

instead of this ...

```nohighlight
cat $line | awk -F '|' {printf "%s|%\n", $5, $3} >> ftp.dat

```

try this ...

```nohighlight
cat $line | awk -F "|" '{printf "%s|%\n", $5, $3}' >> ftp.dat

```

---

<div class="post-metadata">

**Author:** ![k11](https://community.unix.com/letter_avatar/k11/32/6_449c533f586939b6e5f246632a46421f.png) [@k11](https://community.unix.com/u/k11)\
**Post date:** [June 14, 2005, 11:55am UTC](https://community.unix.com/t/awk-syntax-error/154027/4 "2005-06-14T11:55:21Z")

</div>

why? I honestly don't know why echo is correct, please explain.

---

<div class="post-metadata">

**Author:** ![k11](https://community.unix.com/letter_avatar/k11/32/6_449c533f586939b6e5f246632a46421f.png) [@k11](https://community.unix.com/u/k11)\
**Post date:** [June 14, 2005, 11:57am UTC](https://community.unix.com/t/awk-syntax-error/154027/5 "2005-06-14T11:57:18Z")

</div>

changing the single quotes to double did not fix the error, sorry

---

<div class="post-metadata">

**Author:** ![Just\_Ice](https://community.unix.com/user_avatar/community.unix.com/just_ice/32/165_2.png) [@Just\_Ice](https://community.unix.com/u/Just_Ice)\
**Post date:** [June 14, 2005, 12:06pm UTC](https://community.unix.com/t/awk-syntax-error/154027/6 "2005-06-14T12:06:01Z")

</div>

... i think you're missing the single quotes around the curly brackets ... see bold red ...

```nohighlight
cat $line | awk -F "|" '{printf "%s|%\n", $5, $3}' >> ftp.dat

```

---

<div class="post-metadata">

**Author:** ![k11](https://community.unix.com/letter_avatar/k11/32/6_449c533f586939b6e5f246632a46421f.png) [@k11](https://community.unix.com/u/k11)\
**Post date:** [June 14, 2005, 12:18pm UTC](https://community.unix.com/t/awk-syntax-error/154027/7 "2005-06-14T12:18:30Z")

</div>

sorry, those single quotes didn't do the trick either.

---

<div class="post-metadata">

**Author:** ![Just\_Ice](https://community.unix.com/user_avatar/community.unix.com/just_ice/32/165_2.png) [@Just\_Ice](https://community.unix.com/u/Just_Ice)\
**Post date:** [June 14, 2005, 12:24pm UTC](https://community.unix.com/t/awk-syntax-error/154027/8 "2005-06-14T12:24:17Z")

</div>

i actually tested your code on one of my files and it does work as i wrote it ... try the cat-awk line on one of your input files from the command line --- if it works there, it should work in the loop too ... if not, maybe your cat-awk line doesn't really correspond to your input file ...

btw, can you post your actual error?

---

<div class="post-metadata">

**Author:** ![k11](https://community.unix.com/letter_avatar/k11/32/6_449c533f586939b6e5f246632a46421f.png) [@k11](https://community.unix.com/u/k11)\
**Post date:** [June 14, 2005, 12:29pm UTC](https://community.unix.com/t/awk-syntax-error/154027/9 "2005-06-14T12:29:55Z")

</div>

awk: syntax error near line 1  
awk: bailing out near line 1  
Tue 06/14/05 12:16:57 : Loading Database

---

<div class="post-metadata">

**Author:** ![Just\_Ice](https://community.unix.com/user_avatar/community.unix.com/just_ice/32/165_2.png) [@Just\_Ice](https://community.unix.com/u/Just_Ice)\
**Post date:** [June 14, 2005, 12:32pm UTC](https://community.unix.com/t/awk-syntax-error/154027/10 "2005-06-14T12:32:45Z")

</div>

please post your actual code as you wrote it too ...

---

<div class="post-metadata">

**Author:** ![reborg](https://community.unix.com/user_avatar/community.unix.com/reborg/32/167_2.png) [@reborg](https://community.unix.com/u/reborg)\
**Post date:** [June 14, 2005, 2:41pm UTC](https://community.unix.com/t/awk-syntax-error/154027/11 "2005-06-14T14:41:41Z")

</div>

Is this correct, are you sure you done want an 's' after it?

```nohighlight
printf "%s|%\n", $5, $3

```

Anyway the problem you are having is that many versions of awk do not tolerate a space after -F. the command should be

```nohighlight
cat $line | awk -F"|" '{printf "%s|%s\n", $5, $3}' >> ftp.dat
or
cat $line | awk -F\| '{printf "%s|%s\n", $5, $3}' >> ftp.dat
or
cat $line | awk -F"|" '{printf "%s|%s\n", $5, $3}' >> ftp.dat

```

Altough I would probaby just use

```nohighlight
awk -F\| '{print $5"|"$3}' $line >> ftp.dat

```

---

<div class="post-metadata">

**Author:** ![Just\_Ice](https://community.unix.com/user_avatar/community.unix.com/just_ice/32/165_2.png) [@Just\_Ice](https://community.unix.com/u/Just_Ice)\
**Post date:** [June 14, 2005, 9:33pm UTC](https://community.unix.com/t/awk-syntax-error/154027/12 "2005-06-14T21:33:20Z")

</div>

> [@reborg](#):
>
> Anyway the problem you are having is that many versions of awk do not tolerate a space after -F

reborg might be right ... i tested with no spaces after the "-F" as that is how i use the command by default but wrote down the code line as you did it ...

---

<div class="post-metadata">

**Author:** ![k11](https://community.unix.com/letter_avatar/k11/32/6_449c533f586939b6e5f246632a46421f.png) [@k11](https://community.unix.com/u/k11)\
**Post date:** [June 15, 2005, 10:00am UTC](https://community.unix.com/t/awk-syntax-error/154027/13 "2005-06-15T10:00:40Z")

</div>

thanks, that did the trick, those nasty spaces! appreciate the help!
