Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9265245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:01:19+00:00 2026-06-18T14:01:19+00:00

Basically my problem is this, I have a string delimited by periods, I want

  • 0

Basically my problem is this, I have a string delimited by periods, I want to be able to print each word on a new line with the number of times it occurs next to it.

Here is what I have already:
EDIT:

#!/bin/bash
PARAM=$1 
FILE=${1-test.txt}
#echo $FILE

temp=$( tr '\n' '.' <$FILE )

arr=$(echo $temp | tr "." "\n")

for x in $arr
do
    echo "$x"
done

All this does is print out each word on a line. Now I need to count the number of times each word appears and then print it out next to the word. For example:

temp contents = apple, pear, apple, peach

Output should be:

apple 2
pear 1
apple 2
peach 1

where each word is on a new line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:01:20+00:00Added an answer on June 18, 2026 at 2:01 pm

    uniq(1) can probably do what you want. For example:

    $ echo 'foo.bar.baz.bar.foo.box.foo' | tr '.' '\n' | sort | uniq -c
          2 bar
          1 baz
          1 box
          3 foo
    $
    

    Note that uniq requires sorted input to be able to properly count occurrences.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been stumped all day on this problem. Basically I want to check
I have spent hours trying to fix this problem I have, basically I want
Basically i have a problem with this timer program I am trying to put
I have basically the same problem outlined in this question, however I am using
The problem is basically this, in python's gobject and gtk bindings. Assume we have
This is basically a math problem, but very programing related: if I have 1
Without explaining the entire context, my problem is basically this: I have a datagridview
Basically I have the inverse of this problem: Python Time Seconds to h:m:s I
having another short regex problem. Basically I have a string like such: cn=WSG-AP-LO-COMMON-SITE-APPS,ou=ZFD,ou=SVC,ou=IGH I'm
It basically comes down to this. I have a string called $name. $name usually

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.