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 :)
'/' 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.
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.
No comments:
Post a Comment