Wednesday, December 14, 2011

Copy and paste content from one file to another file in VI

Here are steps:

  1. Open the file you need to edit
  2. :sp /path/to/the/file/... and open the file that you need to copy from (this will split the window and open the other file in top section)
  3. Locate the lines you want to copy. If it 10 lines type 10yy
  4. Move to the other file using CTRL+ws
  5. Figure out where you need to paste the yanked lines type p
That's it :)


Tuesday, November 22, 2011

Syntax Highlighting & Word Counter

Syntax highlighting and word count are much needed tools when doing articles/tutorials to wso2.org.

Following are useful links.
syntax highlighting - http://alexgorbatchev.com/SyntaxHighlighter/manual/demo/highlight.html

Word counter - http://www.wordcounttool.com/









Sunday, November 20, 2011

s in sed

I was doing an article where I was copying code snippets from a my editor to the article's editor. When switched on to the HTMl view I noticed that there are <p></p> tags added in my source. I was to delete these away to make my code look neater. sed was my time savor.

sed s command is used like this; say I need to replace cool with crap, the command is;
sed -e 's/cool/crap/g'

So for my task, I copied the code snippet to a temp file and ran folliwing shell script to get my source code cleaned up. Nice and cool, love it :)
sed -e 's/<p>/ /g' temp.txt > temp1.txt
cp temp1.txt temp.txt
sed -e 's/<\/p>/ /g' temp.txt > temp1.txt

'/' is a delimiter in sed, so when you use a regular expression with '/' in it you will need to quote it using a backslash (\).

In above I've said to change <p>in temp.txt to a space and copy the updated code in temp1.txt. Then I copy the updated temp1 content to temp.txt and remove </p>s from it.

Day 03 Gala Dinner Highlight Video