1

I have this bash commands to filter words in a text file (file1 in the example)

Until now i have to use two separate commands to get the result i want

sed -n "SAMPLETEXT" file1 > file2
sort file2 | uniq -c > file2.tmp && mv file2.tmp file2.txt 

because i need to filter out lines with certain strings from file1 and then count all equal lines.

is there a way to do that all in one command to show the output in the console so that i dont need to even create a "file2"?

2 Answers 2

3
sed -n "SAMPLETEXT" file1|sort| uniq -c
Sign up to request clarification or add additional context in comments.

1 Comment

You are welcome. if it helped, you can upvote and accept my answer.
0

You can use grep too:

grep "SAMPLETEXT" file1 | sort | uniq -c

Comments

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.