This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 28th, 2013  |  syntax: None  |  size: 0.85 KB  |  views: 21  |  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. $ echo "Today is XX" | sed -e "s/XX/$(date +%F)/"
  2. Today is 2012-10-11
  3.        
  4. s/XX/Thursday/
  5.        
  6. $ echo "Today is XX" | sed -f replacements.sed
  7. Today is Thursday
  8.        
  9. s/XX/$(date +%F)/
  10.        
  11. $ echo "Today is XX" | sed -f replacements.sed
  12. Today is $(date +%F)
  13.        
  14. cat <<! > replacements.sed
  15. /XX/{s//'"$(date +%F)"'/;s/.*/echo '&'/e}
  16. !
  17. echo "Today is XX" | sed -f replacements.sed
  18.        
  19. cat <<! > replacements.sed
  20. /XX/{
  21.     s//'"$(date +%F)"'/
  22.     s/.*/echo '&'/
  23. }
  24. !
  25. echo "Today is XX" | sed -f replacements.sed | sh
  26.        
  27. aaa
  28. bbb
  29. ccc
  30.        
  31. #!/bin/sh
  32.  
  33. STRING="${1////\/}"   # using parameter expansion to prevent / collisions
  34.  
  35. shift
  36.  
  37. sed "
  38. s/aaa/$STRING/
  39. " "$@"
  40.        
  41. ./sed.sh "fo/obar" <file path>
  42.        
  43. fo/obar
  44. bbb
  45. ccc
  46.        
  47. [ghoti@pc ~/tmp]$ cat scr.sed
  48. 1{;h;d;};/^--$/g
  49. [ghoti@pc ~/tmp]$ sed -f scr.sed <(date '+%Y-%m-%d'; printf 'foon--nbarn')
  50. foo
  51. 2012-10-10
  52. bar
  53. [ghoti@pc ~/tmp]$
clone this paste RAW Paste Data