1.正则匹配使用
#!/usr/bin/env bash
function solution_1() {
local arr=""
while read line; do
arr=(${line})
for ele in ${arr[@]}; do
if [[ "${ele}" =~ B || "${ele}" =~ b ]]; then
continue
fi
echo "${ele} "
done
done < nowcoder.txt
}
function solution_2() {
local arr=""
while read line; do
arr=(${line})
for ele in ${arr[@]}; do
if [[ "${ele}" =~ B|b ]]; then
continue
fi
echo "${ele} "
done
done < nowcoder.txt
}
function solution_4() {
sed '/B\|b/d' nowcoder.txt
}
function solution_5() {
#awk '{ for(i=0; i<NF; i++) if($i ~! /b/) print $i }' nowcoder.txt
#awk '/\+[^b\+]\+/{print $1}' nowcoder.txt
:
}
function solution_999() {
while read line; do
my_array=("${my_array[@]}" $line)
done
declare -a pattern=(${my_array[@]/*[B|b]*/})
echo ${pattern[@]}
}
solution_1