我在名为“ a.txt”,“ b.txt”和“ c.txt”的目录“ dir”中有4个文件。所有文件都包含文本。
a.txt:Chan Chan Man被捕。
b.txt:Chandler Bing被捕。
c.txt:乔伊,鸭子和小鸡抗议钱德勒被捕。
我想从所有文件中删除特定的关键字,并将这些新文件存储在另一个目录“ dir2”中。可以说我要删除“逮捕”和“逮捕”。因此,新文件变为:
aNew.txt:Chan Chan Man是。
bNew.txt:Chandler Bing获得了。
cNew.txt:乔伊(Joey),鸭子和小鸡抗议钱德勒(Chandler)的抗议。
我正在使用Mac Terminal。如果有人能为一般情况提供解决方案,那很好,那就是文件可以放在子目录中,而我可以提供正则表达式列表而不是要删除的关键字。
#!/bin/bash
source=dir
dest=dir2
for file in a.txt b.txt c.txt
do
# Copy the file to the destination directory
cp "$source/$file" "$dest"
# Modify the contents of the file in the destination directory.
sed -i 's/arrested\././' "$dest/$file"
sed -i 's/arrest\././' "$dest/$file"
done
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句