postheadericon unix grep command


Definition : Write a script that deletes all leading and trailing spaces in all lines in a file. Also remove blank lines from a file. Locate lines containing only printf but not fprintf

File Name : ex27.sh


clear
echo "Enter file name : "
read fileName
if [ -f $fileName ]
then
echo "____________________________________"
        echo " Trim File .... "
        echo "____________________________________"

        # Delete leading & trailing whitespace from each line and store it tempFile.txt
        sed 's/^[ \t]*//;s/[ \t]*$//;' $fileName >tempFile.txt

        # Remove all blank lines from tempFile.txt
        sed '/^$/d' tempFile.txt

        # Replace content of this two file
        mv tempFile.txt $fileName
else
        echo "File Not Found"
fi

echo "____________________________________"
echo "  Located Lines .... "
echo "____________________________________"

# Locate lines containing only printf but not fprintf
grep -e "printf" $fileName | grep -v "fprint"

0 comments:

Follow by Email

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.