Advertisement
Guest User

Untitled

a guest
Jan 9th, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.28 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. ## From:
  4. # Hi mom.how is DAD today?when he comes back HOME,tell him to cAll me; else, I will caLL him tomorrow . bye for noW.
  5. #
  6. #
  7. # Hi dad . How are you ??
  8.  
  9. ## to
  10. # Hi mom. How is dad today? When he comes back home, tell him to call me; Else, I will call him tomorrow. Bye for now.
  11. #
  12. # Hi dad. How are you?
  13.  
  14. # PREP = Pre-processing
  15. # POSTP = Post-processing
  16.  
  17. FILE=~/testt
  18. # Read file, TODO: Check it exists?
  19. VALUE=$(cat "$FILE")
  20.  
  21. # Remove duplicates of quoted characters PREP A / B
  22. for i in "?" ";" "!" "," " "; do
  23.    VALUE=$(echo "$VALUE" | tr -s "$i")
  24. done
  25.  
  26. # Lowercase all letters. PREP E
  27. VALUE=$(echo "$VALUE" | tr '[:upper:]' '[:lower:]')
  28.  
  29. # Capitalize first letter at start of line. PREP D (in a way)
  30. VALUE=$(echo "$VALUE" | sed 's/^\s*./\U&\E/g')
  31.  
  32. # Removes all spaces before special chars
  33. VALUE=$(echo "$VALUE" | sed 's/ \([\.!?;]\)/\1/g')
  34.  
  35. # Removes all spaces after special chars
  36. VALUE=$(echo "$VALUE" | sed 's/\([\.!?,;]\)\s/\1/g')
  37.  
  38. # Add spaces after special chars
  39. VALUE=$(echo "$VALUE" | sed 's/\([\.!?,;]\)/\1 /g')
  40.  
  41. # Uppercase chars after special chars (. ! ? ;) PREP D
  42. VALUE=$(echo "$VALUE" | sed 's/[\.!?;]\s*./\U&\E/g')
  43.  
  44. # Uppercase "I"s Not a PREP, but in example output
  45. VALUE=$(echo "$VALUE" | sed 's/\ i\ /\ I\ /g')
  46.  
  47. echo "$VALUE"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement