user1960932
user1960932

Reputation:

Unexpected token error:awk

Hi i have used this code snippet to input a file and count the number of tabs in each line and print the result to output file, but i m getting the error

awk: cmd. line:1: Unexpected token

What could be the mistake

#!/bin/sh
#
FILE='unit-1-slide.txt'
OUTPUTFILE='output-for'-$FILE
COUNT=$(awk '{print gsub(/\t/,"")}'$FILE)
OUTPUT_PATH='/home/user/Desktop'
echo $COUNT > $OUTPUTFILE
echo "Done!"

Upvotes: 2

Views: 8385

Answers (1)

Jens
Jens

Reputation: 72667

There's a space missing before $FILE in

COUNT=$(awk '{print gsub(/\t/,"")}'$FILE)

so the file name is treated as part of the awk script. When the shell performs quote removal the quotes are removed, not replaced with spaces.

Upvotes: 1

Related Questions