如何使用bash文件计算文本文件中的特定单词

问题描述 投票:-1回答:2

我有一个文本文件,其中包含以下文本:

ITEM
preset_date 23/10/15
preset_time 22:00:00:00
title Buletin Awani Headlines
clip TAPE_REPLACEMENT
in_src 0
out_src 1500
mode 2
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 1
user_data 08_P_152784839
logo_data_0 0
channel_id 2
end
ITEM
preset_date 23/10/15
preset_time 22:01:00:00
title Episode Number 7
clip HJNAW01HM01AA
in_src 902250
out_src 915700
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 1
user_data 08_P_152784840
logo_data_0 0
aspect_ratio 2
channel_id 2
use_subtitle 1
subtitle HJNAW01HM01
end

我想计算单词logo在文件中的出现次数。我要如何使用Bash文件实现此目的?感谢您的帮助..

bash
2个回答
0
投票
纯bash解决方案:

#!/bin/bash count=0 match="logo" # note: this is a regular expression while read -a line ; do for word in "${line[@]}" ; do [[ $word =~ $match ]] && let 'count=count+1' done done echo $count


0
投票
grep -c 'logo' < input file name
© www.soinside.com 2019 - 2024. All rights reserved.