Count values of dict-like object in multiple filesWhat is the best way to find a list of several strings within a large text fileCount occurrences of line in multiple filesHelp with using quotes in grep searchesHow to grep between words in a log?Combining strings command and grep: how to limit results to null-terminated stringsExtract all lines from a word to another with my match in betweenHow can I find which csv files are related (i.e., have foreign key references) to others?compare two files and print matches - large filesgrep can't get the word I need, but Linux continues to do the next job. How do I stop it?Find all occurrences of string after another string in all files

How dangerous is XSS

How to show a landlord what we have in savings?

Unlock My Phone! February 2018

What are the G forces leaving Earth orbit?

Does marriage to a non-Numenorean disqualify a candidate for the crown of Gondor?

Mathematica command that allows it to read my intentions

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

how do we prove that a sum of two periods is still a period?

How obscure is the use of 令 in 令和?

What is an equivalently powerful replacement spell for Yuan-Ti's Suggestion spell?

How exploitable/balanced is this homebrew spell: Spell Permanency?

How to compactly explain secondary and tertiary characters without resorting to stereotypes?

How can a day be of 24 hours?

If a warlock makes a Dancing Sword their pact weapon, is there a way to prevent it from disappearing if it's farther away for more than a minute?

Getting extremely large arrows with tikzcd

Am I breaking OOP practice with this architecture?

How can I prove that a state of equilibrium is unstable?

Does the Idaho Potato Commission associate potato skins with healthy eating?

What exactly is ineptocracy?

Why was Sir Cadogan fired?

Placement of More Information/Help Icon button for Radio Buttons

Finitely generated matrix groups whose eigenvalues are all algebraic

Avoiding the "not like other girls" trope?

Are British MPs missing the point, with these 'Indicative Votes'?



Count values of dict-like object in multiple files


What is the best way to find a list of several strings within a large text fileCount occurrences of line in multiple filesHelp with using quotes in grep searchesHow to grep between words in a log?Combining strings command and grep: how to limit results to null-terminated stringsExtract all lines from a word to another with my match in betweenHow can I find which csv files are related (i.e., have foreign key references) to others?compare two files and print matches - large filesgrep can't get the word I need, but Linux continues to do the next job. How do I stop it?Find all occurrences of string after another string in all files













0















I have three txt files that have this format:



File 1:




"username1":10,
"username2":11,
"username3":100,



File 2:




"username1":4,
"username5":15,
"username6":25,



File 3:




"username1":6,
"username2":19,
"username6":25,



I would like a json file (a dict object) containing the sum of the values of each username. That is, I would like:




"username1":20,
"username2":30,
"username3":100,
"username5":15,
"username6":50,



Each username could appear in each file; each username will occur a maximum of 1 time in each file. The string usernamei is an alphanumeric string of length >=1. It could be Stacy60 or evergreen or 0, etc.



That is, if username1 appears in file1, it only appears once in file1; it could appear again in file2 or file3 or both, but only once in each file.



Since these are txt files, I'm having a hard time reading them in as dict objects in Python, and thought there might be a nice grep or cat solution to this. I'm not sure how to get it right, though. I've tried:



grep -o '[[:alnum:]]":"[0-9]+" ./file_*.txt | cut -d '"' f1 | sort | uniq -c > all_usernames.json


It didn't work, and I'm not sure how to fix it.










share|improve this question

















  • 1





    Does the last entry in each object actually have a comma at the end? If so, neither input nor output is valid JSON.

    – Kusalananda
    2 days ago












  • Yes, each entry does have a comma at the end.

    – StatsSorceress
    2 days ago






  • 1





    Python has a good json package that would make short work of this.

    – stolenmoment
    2 days ago











  • Except each input file is not in json format; they're txt files. Does that matter?

    – StatsSorceress
    2 days ago











  • @StatsSorceress There can be various nice solutions through command line, but are you sure you wouldn't like a python solution ? that format is exactly python's format for dict literals and those files can be easily slurped in by a very short and simple python script

    – LL3
    2 days ago















0















I have three txt files that have this format:



File 1:




"username1":10,
"username2":11,
"username3":100,



File 2:




"username1":4,
"username5":15,
"username6":25,



File 3:




"username1":6,
"username2":19,
"username6":25,



I would like a json file (a dict object) containing the sum of the values of each username. That is, I would like:




"username1":20,
"username2":30,
"username3":100,
"username5":15,
"username6":50,



Each username could appear in each file; each username will occur a maximum of 1 time in each file. The string usernamei is an alphanumeric string of length >=1. It could be Stacy60 or evergreen or 0, etc.



That is, if username1 appears in file1, it only appears once in file1; it could appear again in file2 or file3 or both, but only once in each file.



Since these are txt files, I'm having a hard time reading them in as dict objects in Python, and thought there might be a nice grep or cat solution to this. I'm not sure how to get it right, though. I've tried:



grep -o '[[:alnum:]]":"[0-9]+" ./file_*.txt | cut -d '"' f1 | sort | uniq -c > all_usernames.json


It didn't work, and I'm not sure how to fix it.










share|improve this question

















  • 1





    Does the last entry in each object actually have a comma at the end? If so, neither input nor output is valid JSON.

    – Kusalananda
    2 days ago












  • Yes, each entry does have a comma at the end.

    – StatsSorceress
    2 days ago






  • 1





    Python has a good json package that would make short work of this.

    – stolenmoment
    2 days ago











  • Except each input file is not in json format; they're txt files. Does that matter?

    – StatsSorceress
    2 days ago











  • @StatsSorceress There can be various nice solutions through command line, but are you sure you wouldn't like a python solution ? that format is exactly python's format for dict literals and those files can be easily slurped in by a very short and simple python script

    – LL3
    2 days ago













0












0








0


1






I have three txt files that have this format:



File 1:




"username1":10,
"username2":11,
"username3":100,



File 2:




"username1":4,
"username5":15,
"username6":25,



File 3:




"username1":6,
"username2":19,
"username6":25,



I would like a json file (a dict object) containing the sum of the values of each username. That is, I would like:




"username1":20,
"username2":30,
"username3":100,
"username5":15,
"username6":50,



Each username could appear in each file; each username will occur a maximum of 1 time in each file. The string usernamei is an alphanumeric string of length >=1. It could be Stacy60 or evergreen or 0, etc.



That is, if username1 appears in file1, it only appears once in file1; it could appear again in file2 or file3 or both, but only once in each file.



Since these are txt files, I'm having a hard time reading them in as dict objects in Python, and thought there might be a nice grep or cat solution to this. I'm not sure how to get it right, though. I've tried:



grep -o '[[:alnum:]]":"[0-9]+" ./file_*.txt | cut -d '"' f1 | sort | uniq -c > all_usernames.json


It didn't work, and I'm not sure how to fix it.










share|improve this question














I have three txt files that have this format:



File 1:




"username1":10,
"username2":11,
"username3":100,



File 2:




"username1":4,
"username5":15,
"username6":25,



File 3:




"username1":6,
"username2":19,
"username6":25,



I would like a json file (a dict object) containing the sum of the values of each username. That is, I would like:




"username1":20,
"username2":30,
"username3":100,
"username5":15,
"username6":50,



Each username could appear in each file; each username will occur a maximum of 1 time in each file. The string usernamei is an alphanumeric string of length >=1. It could be Stacy60 or evergreen or 0, etc.



That is, if username1 appears in file1, it only appears once in file1; it could appear again in file2 or file3 or both, but only once in each file.



Since these are txt files, I'm having a hard time reading them in as dict objects in Python, and thought there might be a nice grep or cat solution to this. I'm not sure how to get it right, though. I've tried:



grep -o '[[:alnum:]]":"[0-9]+" ./file_*.txt | cut -d '"' f1 | sort | uniq -c > all_usernames.json


It didn't work, and I'm not sure how to fix it.







grep






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









StatsSorceressStatsSorceress

16517




16517







  • 1





    Does the last entry in each object actually have a comma at the end? If so, neither input nor output is valid JSON.

    – Kusalananda
    2 days ago












  • Yes, each entry does have a comma at the end.

    – StatsSorceress
    2 days ago






  • 1





    Python has a good json package that would make short work of this.

    – stolenmoment
    2 days ago











  • Except each input file is not in json format; they're txt files. Does that matter?

    – StatsSorceress
    2 days ago











  • @StatsSorceress There can be various nice solutions through command line, but are you sure you wouldn't like a python solution ? that format is exactly python's format for dict literals and those files can be easily slurped in by a very short and simple python script

    – LL3
    2 days ago












  • 1





    Does the last entry in each object actually have a comma at the end? If so, neither input nor output is valid JSON.

    – Kusalananda
    2 days ago












  • Yes, each entry does have a comma at the end.

    – StatsSorceress
    2 days ago






  • 1





    Python has a good json package that would make short work of this.

    – stolenmoment
    2 days ago











  • Except each input file is not in json format; they're txt files. Does that matter?

    – StatsSorceress
    2 days ago











  • @StatsSorceress There can be various nice solutions through command line, but are you sure you wouldn't like a python solution ? that format is exactly python's format for dict literals and those files can be easily slurped in by a very short and simple python script

    – LL3
    2 days ago







1




1





Does the last entry in each object actually have a comma at the end? If so, neither input nor output is valid JSON.

– Kusalananda
2 days ago






Does the last entry in each object actually have a comma at the end? If so, neither input nor output is valid JSON.

– Kusalananda
2 days ago














Yes, each entry does have a comma at the end.

– StatsSorceress
2 days ago





Yes, each entry does have a comma at the end.

– StatsSorceress
2 days ago




1




1





Python has a good json package that would make short work of this.

– stolenmoment
2 days ago





Python has a good json package that would make short work of this.

– stolenmoment
2 days ago













Except each input file is not in json format; they're txt files. Does that matter?

– StatsSorceress
2 days ago





Except each input file is not in json format; they're txt files. Does that matter?

– StatsSorceress
2 days ago













@StatsSorceress There can be various nice solutions through command line, but are you sure you wouldn't like a python solution ? that format is exactly python's format for dict literals and those files can be easily slurped in by a very short and simple python script

– LL3
2 days ago





@StatsSorceress There can be various nice solutions through command line, but are you sure you wouldn't like a python solution ? that format is exactly python's format for dict literals and those files can be easily slurped in by a very short and simple python script

– LL3
2 days ago










0






active

oldest

votes












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f509758%2fcount-values-of-dict-like-object-in-multiple-files%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f509758%2fcount-values-of-dict-like-object-in-multiple-files%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.