Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Question
- Guys, Iām far from a regex expert. Where should I start if I want to convert my file with text like
- ```This is a text```
- to
- ```<span id="f001">This</span><span id="f002"> is</span><span id="f003"> a</span><span id="f004"> text</span>```
- ## Solution
- ```$ 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"
- <span id="f001">This</span> <span id="f002">is</span> <span id="f003">a</span> <span id="f004">text</span>
- ```
- Whoops, I missed a space:
- ```ā 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"
- <span id="f001">This</span><span id="f002"> is</span><span id="f003"> a</span><span id="f004"> text</span>
- ```
- Note: gsed is just GNU sed on OSX, if you brew install coreutils
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement