一个删除匹配的记录的shell脚本
时间:2014-10-20 23:39 来源:linux.it.net.cn 作者:it
这个脚本将以一个特定的模式来搜索一个目录中的每个文件,然后删除该模式匹配的记录。
用到的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
(责任编辑:IT)
这个脚本将以一个特定的模式来搜索一个目录中的每个文件,然后删除该模式匹配的记录。
代码:
#!/bin/sh
(责任编辑:IT)# 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 |