I have been trying to get a maximum and a minimum value in the text file that have a numerical table. In order to do this, I opened up each column in the file using awk function for loop. But I got this error below. I am beginner to use awk, and I cannot find what the problem is. Please help me out!
I got stuck in this problem with:
awk: line 1 : syntax error at or near {
awk: line 1 : syntax error at or near }
awk: line 1 : syntax error at or near {
awk: line 1 : syntax error at or near }
This is my script:
#!/bin/bash
for i in {1..11}
do
#print minimum value in the text file.
awk -F' ' '{print ${i}}' [filename].txt | sort -n | head -1
#print maximum value in the text file.
awk -F' ' '{print ${i}}' [filename].txt | sort -n | tail -1
done
${1}
is not correct. Use$1
instead. I am not sure what you mean with[filename]
, by the way. It's syntactically correct, but it resolves either to a list of files with single-character namesa
,e
,f
,i
,l
,m
orn
, or to the literal string[filename]
; none of which is likely to be your intention.sort -n $filename | head -1 | cut -f1 -d' '
. Or useawk
's processing power for finding the maximum and minimum in one pass withouthead
,tail
andsort
.awk
. What does an input file look like?*.txt
isn't a filename. It's a glob that may or may not match one or more filenames. If your code refers to a single file I'd put a single file in there, e.g.example.txt