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.



#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.
# Save  New.sh


clear

echo -n "Enter name of the file :"
read filename

    if [ ! -f $filename ]
    then
        echo "File does not exist"
    else
        str=$(cat $filename)
        #remove leading and trailing spaces
        str=$(echo "$str" | sed 's/^[ \t]*//;s/[ \t]*$//')
        #remove blank line
        str=$(echo "$str" | sed '/^$/d')
        echo "$str" > $filename
        cat "$filename"
        echo "File transformed successfully"
        echo "PRINTF STATEMENT IS AT LINE "
        echo $(cat $filename | grep -v "fprintf" | grep -iwn "printf")
    fi




new.txt


Hello   MAC    Welcome


Good Morning


OutPut



EmoticonEmoticon