2013年2月6日 星期三

[Sed] Sed the sed file

Purpose:
Remove hash (#) at front of the line
sed -e '^#' -i xxx.txt

Remove space / tab line
sed -e '^$' -i xxx.txt
Purpose:

I want replace some string in another sed file.

So I create another sed file to replace some string which I want.

Create a Sed file is called abc.txt
sed 's|>'"$var"'|>'"$Do"'|g'  -i abc.txt

Create another Sed file is called bcd.txt
Before_Do_Happy=">'\"\$var\"'\|>'\"\$Do\"'"
After_Do_Happy=">'\"\$var\"'<\|>'\"\$Do\"'<"

sed 's|'"$Before_Do_Happy"'|'"$After_Do_Happy"'|g'  -i bcd.txt


Grep piping into sed, replacing inline

grep -rl "general.js" . | xargs   sed  -i   's|general.js|js\/general.js|g'


To remove all blank line & whitespace (include tabs)
sed -e '/^$/d' -i Happy.asp      # To remove all blank lines
sed -e 's/^[ \t]*//' -i Happy.asp # To remove all whitespace (including tabs) from left to first word

Reference:

0 意見:

張貼留言