• Source
    1. #
    2. #Write a script that deletes all leading and trailing spaces in all lines in a file. Also remove blank lines
    3. #from a file. Locate lines containing only printf but not fprintf.
    4. #
    5. clear
    6.  
    7. echo -n "Enter name of the file :"
    8. read filename
    9.  
    10. if [ ! -f $filename ]
    11. then
    12. echo "File does not exist"
    13. else
    14. str=$(cat $filename)
    15. #remove leading and trailing spaces
    16. str=$(echo "$str" | sed 's/^[ \t]*//;s/[ \t]*$//')
    17.  
    18. #remove blank line
    19. str=$(echo "$str" | sed '/^$/d')
    20. echo "$str" > $filename
    21. cat "$filename"
    22. echo "File transformed successfully"
    23. echo "PRINTF STATEMENT IS AT LINE "
    24. echo $(cat $filename | grep -v "fprintf" | grep -iwn "printf")
    25. fi
    26.