0

I have a file called foo.txt, which consists of:

abc
zaa
asd
dess
zaa
abc
aaa
zaa

I want the output to be stored in another file as:

this text abc appears 2 times
this text zaa appears 3 times

I have tried the following command, but this just writes duplicate entries and their number.

sort foo.txt | uniq --count --repeated > sample.txt

Example of output of above command:

abc 2
zaa 3

How do I add the line "this text appears x times" ?

1 Answer 1

2

Awk is your friend:

sort foo.txt | uniq --count --repeated | awk '{print($2" appears "$1" times")}'
Sign up to request clarification or add additional context in comments.

1 Comment

Thanku !!Worked well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.