Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. # Question
  2.  
  3. Guys, I’m far from a regex expert. Where should I start if I want to convert my file with text like
  4. ```This is a text```
  5. to
  6. ```<span id="f001">This</span><span id="f002"> is</span><span id="f003"> a</span><span id="f004"> text</span>```
  7.  
  8.  
  9. ## Solution
  10.  
  11. ```$ echo "This is a text" | gsed -r 's/(\w+)/<span id="f00\n">\1<\/span>/g' | nl -b 'p/span' -s '' -w1 | tr -d "\n"
  12. <span id="f001">This</span> <span id="f002">is</span> <span id="f003">a</span> <span id="f004">text</span>
  13. ```
  14.  
  15. Whoops, I missed a space:
  16.  
  17. ```○ echo "This is a text" | gsed -r 's/( ?\w+)/<span id="f00\n">\1<\/span>/g' | nl -b 'p/span' -s '' -w1 | tr -d "\n"
  18. <span id="f001">This</span><span id="f002"> is</span><span id="f003"> a</span><span id="f004"> text</span>
  19. ```
  20.  
  21. Note: gsed is just GNU sed on OSX, if you brew install coreutils
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement