Results 1 to 2 of 2
I have a file which contains 5 columns of demographic data with column headings. The table has 5 rows of data all stored in a text file. The second column ...
- 03-24-2011 #1Just Joined!
- Join Date
- Mar 2011
- Posts
- 5
awk command
I have a file which contains 5 columns of demographic data with column headings. The table has 5 rows of data all stored in a text file. The second column contains numerical data, however it has imbedded commas; i.e. 123,456,789. I would like to use awk or gawk to output the total of all of the numbers. I know how to set it up for another column which has no commas in the data and get the correct result.
If I only have a single column with the data in it I was able to get the desired result with this command:
gawk --posix -F, '/^,/ (tot+=$1 $2 $3); END{print tot}' file.txt
The computer echo'd each row and then printed the total at the bottom. My challenge is how do I get it to ignore the first column and use the second column in the original file.
Can anyone help with this problem? Thanks.
LarryLast edited by larry3639; 03-24-2011 at 08:51 PM.
- 04-21-2011 #2Just Joined!
- Join Date
- Apr 2011
- Posts
- 14
Is there any reason why you don't want to do this:
If you want to completely ignore the first column printing and summing then try this:Code:gawk --posix -F, '/^,/ (tot+=$2 $3); END{print tot}' file.txt
Code:cat file.txt|awk -F, '{print $2","$3}'|awk -F, '(tot+=$1 $2); END{print tot}'


Reply With Quote
