SED and TR command line tools are very useful tools to perform various text manipulations in Linux. You can also find them on Mac OS X, however be aware that they could work a little differently from the same tools on Linux OS. Two very simple, but extremely useful one-liners (tested on Linux Ubuntu OS). The first one is wrapping your text with a div tag and "lazyload" class, also it wraps the text into HTML comment tags. The second one-liner is removing all newline characters from the text.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Wrap text with lazyload class: | |
sed '1s/^\(.*\)$/<div class=\"lazyload\">\n<\!\-\-\n\1\n\-\->\n<\/div>/' | |
# Remove all newlines from the text: | |
tr -d '\n' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sed '1s/^\(.*\)$/<div class=\"lazyload\">\n<\!\-\-\n\1\n\-\->\n<\/div>/' | |
Hello World! | |
<div class="lazyload"> | |
<!-- | |
Hello World! | |
--> | |
</div> |