input file name:checkbook.txt (fields are tab separated)
1000
125 Market 125.45
126 Hardware Store 34.95
127 Video Store 7.45
128 Book Store 14.32
129 Gasoline 16.10
I need first record first field only
For the above file I get differnce in output as below:
1. I tried below command and it worked:
[oracle@localhost scripts]$ awk 'NR==1 { print $1 }' /home/oracle/Documents/myprojects/Documents/dir2/checkbook.txt
1000
2. The same command in a file Checkbook.awk gives output:
[oracle@localhost scripts]$ awk -f Checkbook.awk /home/oracle/Documents/myprojects/Documents/dir2/checkbook.txt
1000
1000
125
126
127
128
129
End
Code in Checkbook.awk
[oracle@localhost scripts]$ cat Checkbook.awk
BEGIN {
}
NR==1
{
print $1
}
END {
print "\n\nEnd"
}
Also tried altering the Checkbook.awk as below,
[oracle@localhost scripts]$ cat Checkbook.awk
NR==1
{
print $1
}[oracle@localhost scripts]$ awk -f Checkbook.awk /home/oracle/Documents/myprojects/Documents/dir2/checkbook.txt
1000
1000
125
126
127
128
129
[oracle@localhost scripts]$
Why is difference in output?
Please help to resolve it.
Regards,
1000
125 Market 125.45
126 Hardware Store 34.95
127 Video Store 7.45
128 Book Store 14.32
129 Gasoline 16.10
I need first record first field only
For the above file I get differnce in output as below:
1. I tried below command and it worked:
[oracle@localhost scripts]$ awk 'NR==1 { print $1 }' /home/oracle/Documents/myprojects/Documents/dir2/checkbook.txt
1000
2. The same command in a file Checkbook.awk gives output:
[oracle@localhost scripts]$ awk -f Checkbook.awk /home/oracle/Documents/myprojects/Documents/dir2/checkbook.txt
1000
1000
125
126
127
128
129
End
Code in Checkbook.awk
[oracle@localhost scripts]$ cat Checkbook.awk
BEGIN {
}
NR==1
{
print $1
}
END {
print "\n\nEnd"
}
Also tried altering the Checkbook.awk as below,
[oracle@localhost scripts]$ cat Checkbook.awk
NR==1
{
print $1
}[oracle@localhost scripts]$ awk -f Checkbook.awk /home/oracle/Documents/myprojects/Documents/dir2/checkbook.txt
1000
1000
125
126
127
128
129
[oracle@localhost scripts]$
Why is difference in output?
Please help to resolve it.
Regards,