Search Results

Search: Posts Made By: paresh n doshi
4,167
Posted By Yoda
I would suggest using $1 and $2 instead of $0 to...
I would suggest using $1 and $2 instead of $0 to discard any blank spaces in any record:
awk '!A[$1,$2]++' file
4,167
Posted By Klashxx
Try: sort -un inputfile
Try:
sort -un inputfile
4,167
Posted By Lucas_0418
Hi guy, As anbu123 said, if your data is...
Hi guy,
As anbu123 said, if your data is sorted, you code is correct.
Mostly we do this to select non-duplicate records
awk '!a[$1]++' inputfile
1,934
Posted By Don Cragun
Note that although you need to remove the commas...
Note that although you need to remove the commas from your input before adding the values to your total, awk is happy to print your results with or without thousands separators. As an example, if...
1,934
Posted By Akshay Hegde
In first command var=$1 and then gsub is used it...
In first command var=$1 and then gsub is used it means $1 will remain unchanged, in second command if $1 contains , then its removed, and $1 itself will be modified

look at the difference copy of...
1,934
Posted By RudiC
That var will hold the count of substitutions...
That var will hold the count of substitutions that gsub has made on the string it worked upon. The string itself will be modified and thus holds the result.
1,934
Posted By Akshay Hegde
Try like this $ printf "%s\n%s\n" 10,250.00...
Try like this

$ printf "%s\n%s\n" 10,250.00 20,103.15 | awk '{var=$1;gsub(/,/,x,var);print var}'
10250.00
20103.15


if you assign directly as greet_sed said it gives you a count of...
1,934
Posted By greet_sed
you can. variable will results in to number of...
you can.
variable will results in to number of times the substitution has been made.
For ex:
echo "hi,this,is,name" | awk '{ a=gsub(/,/,"");print a}'
3
1,934
Posted By Subbeh
remove the commas: awk...
remove the commas:
awk '{gsub(/,/,"");subtot+=$1}END{print subtot}' file
1,934
Posted By Akshay Hegde
Try $ awk '{sum+=$1}END{print sum}' file ...
Try

$ awk '{sum+=$1}END{print sum}' file

if comma is there then use this

$ printf "%s\n%s\n" 10,250.00 20,103.15 | awk '{gsub(/,/,x,$1);sum+=$1}END{print sum}'
30353.2
7,761
Posted By Don Cragun
Reformatting Scrutinizer's code and adding...
Reformatting Scrutinizer's code and adding comments:
awk ' # invoke awk program and start script to be run by awk
/Output view:/ {# When an input line contains the string "Output...
Showing results 1 to 11 of 11

 
All times are GMT -4. The time now is 05:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy