linux - 如何打印文件中的出现次数?

标签 linux bash shell

我使用此代码从以 wt^ 和 p^ 开头的文件中读取行,该文件包含 900 wt^ 和 p^ 行,它在每个文件中打印 200 行。但我想要的是读取 200 wt^ 及其相应的 p^。

基本上我想在一个文件中打印 200 wt^ 及其相应的 p^ 这个怎么做?

文件是这样的

wt^fsafasfafasffaferer
  p^pap rar otaotetae
  p^pap rar otaotetae
  p^pap rar otaotetae
  p^pap rar otaotetae
  p^pap rar otaotetae
  p^pap rar otaotetae

代码:

while IFS= read file
do 
    if [ -f "$file" ]; then
    count=$(cat $( ls unit-*-slides.txt | sort -n ) | grep -E "[ ]*(wt\^|p\^)" | split -l 200)
    fi
done < "$dest/$cfile"

最佳答案

$ awk NF=NF FPAT='.*\\^'
wt^
  p^
  p^
  p^
  p^
  p^
  p^

关于linux - 如何打印文件中的出现次数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16400354/

相关文章:

linux - 全文索引并将列设置为 sphinx 中的属性?

python - 散列多个文件

android - 在 sh 中为 Android 定义一个数组

linux - inotify兼容的shell脚本监控某个目录的shell

linux - bash 脚本返回空的 ps 结果,CLI 上相同的一行正确返回

linux - 这个蛋糕上的命令是做什么的?

bash - shell 脚本 : Iterating over array of json

bash - 对于文件夹中的每个目录,在不同的位置创建一个目录

linux - 如何在shell中加入两个文件

linux - vmstat : What exactly does cpu wait mean?