#!/bin/bash
# output the file, if find root , then print root in the output file
sed -n '/root/p' ./passwd > output
FILE='output'
# determine the file, if file is empty then no find
if [ -s $FILE ] ; then
echo "$FILE has data."
rm $FILE
else
echo "$FILE is empty."
rm $FILE
fi
Reference :
sed - Stream EDitor - works as a filter processing input line by line.
check if file is empty
Unix - Regular Expressions with SED
0 意見:
張貼留言