Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 10th, 2012  |  syntax: None  |  size: 0.89 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Bash Sorting STDIN
  2. #!/bin/bash
  3.  
  4. inp=0 echo "Which filename for strings?"
  5. read strg
  6. touch $strg
  7. echo "Which filename for nums?"
  8. read nums
  9. touch $nums
  10. echo "Which filename for alphanumerics?"
  11. read alphanums
  12. touch $alphanums
  13. while [ "$inp" != "quit" ]
  14. do
  15.  echo "Input: "
  16.  read inp
  17.  echo $inp | grep -o '<[a-zA-Z]+>' > $strg
  18.  echo $inp | grep -o '<[0-9]>' > $nums
  19.  echo $inp | grep -o -E '<[0-9]{2,}>' > $nums
  20. done
  21.        
  22. $ grep -o '<[a-zA-Z]+>' sorting_input
  23. this
  24. is
  25. a
  26. string
  27. containing
  28. words
  29. single
  30. digits
  31. as
  32. in
  33. and
  34. as
  35. well
  36.        
  37. $ grep -o '<[0-9]>' sorting_input
  38. 1
  39. 2
  40.        
  41. $ grep -o -E '<[0-9]{2,}>' sorting_input
  42. 42
  43. 1066
  44.        
  45. <input_file strings -1 -a | tee chars_and_strings.txt |
  46. grep "^[A-Za-z0-9][A-Za-z0-9]*$" | tee alphanum.txt |
  47. grep "^[0-9][0-9]*$" > numonly.txt
  48.        
  49. #!/bin/bash
  50.  
  51. cat > temp
  52.  
  53. grep pattern1 > file1
  54. grep pattern2 > file2
  55. grep pattern3 > file3
  56.  
  57. rm -f temp
  58.        
  59. cat file_to_process | ./script.sh