Using sed to remove lines from multiple files
In addition to searching and replacing content in files, Sed can also remove specific characters from files. This can be done by specifying the '/d' option after the pattern you specific. Below is a script which deletes the DTD header for a list of files in a specific directory using the Sed command:
##########################################################
#
# Script used to delete the DOCTYPE header consisting of
# the dtd file path from each xml in a specified directory
#
##########################################################
INPUT_DIR=$1
for filename in $INPUT_DIR/*.xml
do
echo "removing dtd path for $filename ...."
sed -e '/DOCTYPE/d' $filename > $INPUT_DIR/temp_file
mv -f $INPUT_DIR/temp_file $filename
done
##########################################################
#
# Script used to delete the DOCTYPE header consisting of
# the dtd file path from each xml in a specified directory
#
##########################################################
INPUT_DIR=$1
for filename in $INPUT_DIR/*.xml
do
echo "removing dtd path for $filename ...."
sed -e '/DOCTYPE/d' $filename > $INPUT_DIR/temp_file
mv -f $INPUT_DIR/temp_file $filename
done
Labels: unix
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home