相关疑难解决方法(0)

从bash中的句子中删除特定单词?

我想使用 bash 脚本从句子中删除否定词。

我的意思是消极的话:

[dull,boring,annoying,bad]
Run Code Online (Sandbox Code Playgroud)

我的文件文本text.txt包含这句话:

These dull boring cards are part of a chaotic board game ,and bad for people 
Run Code Online (Sandbox Code Playgroud)

我正在使用这个脚本

array=( dull boring annoying bad  )
for i in "${array[@]}"
do
cat $p  | sed -e 's/\<$i\>//g' 
done < my_text.txt
Run Code Online (Sandbox Code Playgroud)

但是我得到了以下错误的结果:

These boring cards are part of a chaotic board game ,and bad for people 
Run Code Online (Sandbox Code Playgroud)

正确的输出必须是这样的:

These cards are part of a chaotic board game ,and for people 
Run Code Online (Sandbox Code Playgroud)

bash shell sed

3
推荐指数
1
解决办法
119
查看次数

在 Shell 脚本中将文件中的字母更改为大写

我正在尝试将文件中的特定给定字母更改为大写,但我不知道该怎么做。该文件已经存在,我想执行以下操作

cat merry.txt 
I wish you a Merry Christmas
Run Code Online (Sandbox Code Playgroud)

将 e 更改为 E,因此输出将是

cat merry.txt
I wish you a MErry Christmas
Run Code Online (Sandbox Code Playgroud)

谢谢大家

linux shell ubuntu-20.04

0
推荐指数
1
解决办法
76
查看次数

标签 统计

shell ×2

bash ×1

linux ×1

sed ×1

ubuntu-20.04 ×1