need to get the total # of column for each line - NF not working
Hello,
I just need to print the # of columns for each line of the input file.
The input file uses the ascii 009 tab character.
I specify this character as the FS (field separator) in the BEGIN section, and I know the FS character is correct because I can print it.
When I try to print the # of columns using NF it always prints the #1.
If I try to print using $NF it prints the whole line in the input file.
It is a UNIX shell script that takes parameters from the command line.
The input file is in the same dir as the script. It is called i.txt.
The input file contains:
The source code is this:
The name of the script is f.sh.
I execute the script from the command line like this:
The resulting output file contains this:
As you can see, there are 9 lines in the input file and 9 lines in the output files.
This is correct however there # 1 is wrong.
Instead of the # 1 it should be the # of columns in that line with the column separator being the ascii 009 tab character.
Hi
i need to calculate the total of a column from a file in ksh
vi file.txt
System : CBSE ent=0.1 me=Cap
Subject Maths Science
xxxxx 56 98
yyyy 89 67
ooo 67 32
Here i need to calculate only the total of Maths column alone i.e., 56+89+67
... (4 Replies)
Hi I have this file which contains
Al,AADESH,id1_0,23,2013-01-28,2,2
Al,AADESH,id1_0,23,2013-01-29,4,4
Al,AADESH,id1_0,23,2013-01-30,2,1
Al,AADESH,id1_0,31,2013-01-29,1,1
Al,AESH,id1_0,31,2013-01-31,2,2
Al,AESH,id2_2,23,2013-01-29,1,1
Al,AESH,id2_2,31,2013-01-31,1,1 ... (5 Replies)
Input file
11916 30640 9320 51876
5690 15874 4723 26287
5121 12269 2569 19959
9 71 6 86
Desired output file
11916 30640 9320 51876
5690 15874 4723 26287
5121 12269 2569 19959
9 71 6 86
22736 58854 16618 98208
Last part is the total up of first three data.
I used the following... (6 Replies)
Input file
data US 100.25
data ENG 235.01
data US 23.12
data ENG 23.01
END UK 230.50
END Russia 20.00
.
.
Desired output
data US 123.37
data ENG 258.02
END UK 230.50
END Russia 20.00
.
. (1 Reply)
Here is my file name countries
USSR 8650 262 Asia
Canada 3852 24 North America
China 3692 866 Asia
USA 3615 219 North America
Brazil 3286 116 South America
India 1269 637 Asia
Argentina 1072 ... (8 Replies)
Hi, i have a file which content the following:
>cat cols
data a:23:data
data b:76:data
data c:-30:data
i would like to sum up the value of column 2, but the result that return to me is 0. Can anyone help?
i'm using this code to do the sum
awk -F" " 'BEGIN {x=0} {x+=$2} END {print... (5 Replies)