简体   繁体   中英

combine sed and sort commands in bash script

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"?

sed -n "SAMPLETEXT" file1|sort| uniq -c

您也可以使用grep:

grep "SAMPLETEXT" file1 | sort | uniq -c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM