How to sum numbers by a specific word separated by semi colon in bash [duplicate]

Uncategorized
Question: This question already has an answer here:GROUP BY/SUM from shell 5 answers How can I sum values in column based on the value in another column? 5 answers To be more specific on the path for instance i have file as below; file.txt apple;10; tomato;5; apple;5; banana;10; banana;5; tomato;10; banana;10; apple;5; I want to sum numbers by item using bash as a result ; file.output apple;20; banana;25; tomato;15; Another word is i need to simplify the file. How can achieve this kind of output as a separate file in bash ? Thanks in advance. Answer: try following awk, if you need output in same sequence as Input_file then following may help you in same. awk -F";" '!a[$1]{b[++i]=$1} {a[$1]+=$2;} END{for(j=1;j
Read More

Make a new prop in socket io object and get undefined

Uncategorized
Question: I was trying to store data into a socket prop that I can reference it later. However, on others socket.on it comes out as undefined Here is the code:var userlist = ['Dang Huy','Alice','Bui Sam', 'Hai Hai']; var onlineUser = []; io.on('connection', socket => { socket.on('userOnline', (data) => { //User Alice go in if(userlist.includes(data)){ onlineUser.push(data); io.sockets.emit('onlineUser', onlineUser); } socket.user_name = data; // store data into user_name console.log(socket.user_name + ' is online'); //logout Alice is online }) socket.on('userSendMessage', (data) => { console.log(socket.user_name) // socket.user_name is undefined here!! console.log(data) // still log out the message from the client side io.sockets.emit('serverSendMessage', 'Hello') }) socket.on('disconnect', function(){ onlineUser.splice(onlineUser.indexOf(socket.user_name), 1) io.sockets.emit('onlineUser', onlineUser) }) }) Answer: What do you mean by next event (could you provides an example?)Oh I notice something very wrong , you won't never…
Read More

Define code sections in sql managment studio

Uncategorized
Question: I have a very long script in sql. I'm working with SSMS 2012 and sql servr 2012. The sturctre is somewhere like this:--Loans_Group --2013 create view Loans_2013 ( select * from X where yr=2013 ) go --2014 create view Loans_2014 ( select * from X where yr=2014 ) go --2015 create view Loans_2015 ( select * from X where yr=2015 ) go --2016 create view Loans_2016 ( select * from X where yr=2016 ) go --2017 create view Loans_2017 ( select * from X where yr=2017 ) go --Credit scoring Group --2013 create view CS ( select * from Y where yr=2013 ) go --2014 create view CS where yr=2014 ( select * from Y ) go --2015 create view CS ( select * from Y where yr=2015 )…
Read More

Window service configuration

c#
Question: I am using a window service with a wshttpbinding, and am getting the below error when trying to retrieve records via my hosting service.Even though it works on localhost, couldn't work on server. An unhandled exception of type 'System.ServiceModel.Security.SecurityNegotiationException' occurred in mscorlib.dll Additional information: The caller was not authenticated by the service. Server configuration is : On Client reference configuration : Answer: Read more
Read More

Android getting empty first activity when device is rotated is Second Activity and back button is pressed beside using LoaderManager in First Activity

Uncategorized
Question: The title of question might be a bit confusing but being a beginner I find it tough to write an accurate title. Now coming to the point I am making an app that fetches data from google books api and shows them in a RecyclerView. Data is loaded in the RecyclerView after the click of the search button. When I click on Individual Item of the adapter it opens a DetailActivity. The app works fine If I rotate the device in MainActivity but If I rotate the device in DetailActivity and then press back button the MainActivity adapter is empty. MainActivity.java package com.example.setha.booklisting; import android.app.LoaderManager; import android.content.Context; import android.content.Intent; import android.content.Loader; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.View; import android.widget.Button;…
Read More