这个脚本将以一个特定的模式来搜索一个目录中的每个文件,然后删除该模式匹配的记录。
用到的sed命令与正则。
代码:
复制代码 代码示例:
#!/bin/sh
# This script will search every file in a directory for a
# specific pattern and will delete the records that
# matches with that pattern
directory=$1
pattern=$2
for FILE in `ls $directory`
do
echo "$FILE"
FILPATH="$directory"/"$FILE"
sed ''/$pattern/'d' $FILPATH > "$directory/$FILE.new"
done