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 7165605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:16:40+00:00 2026-05-28T14:16:40+00:00

From wikipedia: uniq -c Generate an output report in default style except that each

  • 0

From wikipedia:

uniq
-c Generate an output report in default style except that each line is preceded by a count of the number of times it occurred. If this option is specified, the -u and -d options are ignored if either or both are also present.

On my machine it is taking the count number and putting it on the start of each line. What I want is for it to be placed at the end of the line, after a comma. How can this be done?

Example:

aa
aa
bb
cc
cc
dd

Should change to:

aa,2
bb,1
cc,2
dd,1
  • 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-05-28T14:16:40+00:00Added an answer on May 28, 2026 at 2:16 pm

    You can try something like this –

    awk '{a[$1]++}END{for (i in a) print i,a[i] | "sort"}' OFS="," filename
    

    or

    awk -v OFS="," '{print $2,$1}' <(uniq -c file)
    

    or

    uniq -c file | awk '{printf("%s,%s\n",$2,$1)}'
    

    or

    while IFS=' +|,' read count text; do 
        echo "$text, $count"; 
    done < <(uniq -c tmp)
    

    Test:

    [jaypal:~/Temp] cat file
    aa
    aa
    bb
    cc
    cc
    dd
    
    [jaypal:~/Temp] awk '{a[$1]++}END{for (i in a) print i,a[i] | "sort"}' OFS="," file
    aa,2
    bb,1
    cc,2
    dd,1
    

    Test2:

    [jaypal:~/Temp] awk -v OFS="," '{print $2,$1}' <(uniq -c file)
    aa,2
    bb,1
    cc,2
    dd,1
    

    Test3:

    [jaypal:~/Temp] while IFS=' +|,' read count text; do 
    echo "$text,$count"; 
    done < <(uniq -c tmp)
    aa,2
    bb,1
    cc,2
    dd,1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From Wikipedia : Generic programming is a style of computer programming in which algorithms
From wikipedia : During each sprint, typically a two to four week period (with
I know from wikipedia for example that exception handling is used in an application
I'm extracting a string from wikipedia API that initially looks like this: link text
I'm using read line to get some text from wikipedia. But read line only
from Wikipedia : Lexicographical order generation For every number k, with 0 ≤ k
Using this example coming from Wikipedia, in which DrawSquare() calls DrawLine() : (Note that
Here's an example from wikipedia that displays C++ template meta-programming: template <int N> struct
From Wikipedia, I read: Joux[3] noted that 2-collisions lead to n-collisions: if it is
From Wikipedia, the free encyclopedia: Closure (computer science) In computer science, a closure is

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.