$ cat read.sh
#!bin/bash
// how can I read the columnwise data to awk-script?
awk '{sum+=$1} END {print sum}' read
$ cat data
1
2
3
4
5
$ . ./read.sh <data
awk: cmd. line:1: fatal: cannot open file `read' for reading (No such file or directory)
$ cat read.sh #!bin/bash // how can I read the columnwise data to awk-script?
Share
Remove the
filenamefrom the end of theawkcommand:Change
to
The 1st one tell
awkto get the input from a file namedreadwhere as the 2nd one tellsawkto get the input fromstandard input.The way you are running the script:
./read.sh <dataYou are supplying the input through standard input.
Alternatively if you always want the script to read input from the file named
data, you can do:and run the script as:
./read.sh