Reputation:
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
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