Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. sed -r 's/([A-Z]+):(.*)/1:U2/;s/([A-Z][a-z]+):([a-z])/1:U2L/' file
  2.  
  3. $ cat case.awk
  4. /^[[:lower:]]+$/ { print "lower"; next }
  5. /^[[:upper:]]+$/ { print "upper"; next }
  6. /^[[:upper:]][[:lower:]]+$/ { print "capitalized"; next }
  7. /^[[:alpha:]]+$/ { print "mixed case"; next }
  8. { print "non alphabetic" }
  9.  
  10. Jims-MacBook-Air so $ echo chihuahua | awk -f case.awk
  11. lower
  12.  
  13. Jims-MacBook-Air so $ echo WOLFHOUND | awk -f case.awk
  14. upper
  15.  
  16. Jims-MacBook-Air so $ echo London | awk -f case.awk
  17. capitalized
  18.  
  19. Jims-MacBook-Air so $ echo LaTeX | awk -f case.awk
  20. mixed case
  21.  
  22. Jims-MacBook-Air so $ echo "Jaws 2" | awk -f case.awk
  23. non alphabetic
  24.  
  25. BEGIN { OFS = FS = ":" }
  26. $1 ~ /^[[:lower:]]+$/ { print $1, tolower($2); next }
  27. $1 ~ /^[[:upper:]]+$/ { print $1, toupper($2); next }
  28. $1 ~ /^[[:upper:]][[:lower:]]+$/ { print $1, toupper(substr($2,1,1)) tolower(substr($2,2)); next }
  29. $1 ~ /^[[:alpha:]]+$/ { print $1, $2; next }
  30. { print $1, $2 }
  31.  
  32. $ echo BEHAVIOUR:behavior | awk -f case.awk
  33. BEHAVIOUR:BEHAVIOR
  34.  
  35. $ echo Behaviour:behavior | awk -f case.awk
  36. Behaviour:Behavior
  37.  
  38. $ echo behaviour:behavior | awk -f case.awk
  39. behaviour:behavior
  40.  
  41. awk -F ':' '
  42. {
  43. # read Pattern to reproduce
  44. Pat = $1
  45. printf("%s:", Pat)
  46.  
  47. # generic
  48. if ( $1 ~ /^[:upper:]*$/) { print toupper( $2); next}
  49. if ( $1 ~ /^[:lower:]*$/) { print tolower( $2); next}
  50.  
  51. # Specific
  52. gsub( /[^[:upper:][:lower:]]/, "~:", Pat)
  53. gsub( /[[:upper:]]/, "U:", Pat)
  54. gsub( /[[:lower:]]/, "l:", Pat)
  55.  
  56. LengPat = split( Pat, aDir, /:/)
  57.  
  58. # print with the correponsing pattern
  59. LenSec = length( $2)
  60.  
  61. for( i = 1; i <= LenSec; i++ ) {
  62. ThisChar = substr( $2, i, 1)
  63.  
  64. Dir = aDir[ (( i - 1) % LengPat + 1)]
  65. if ( Dir == "U" ) printf( "%s", toupper( ThisChar))
  66. else if ( Dir == "l" ) printf( "%s", tolower( ThisChar))
  67. else printf( "%s", ThisChar)
  68. }
  69. printf( "n")
  70. }' YourFile
  71.  
  72. sed -r '/^([^:]*):1$/Is//1:1/' file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement