Linux/sed

Delete empty lines, and search lines: $ sed '/^$/d' /tmp/data.txt $ sed '/^$/d' /tmp/data.txt > /tmp/output.txt $ sed '/Windows/d' /tmp/data.txt > /tmp/output.data.txt

Multiple: echo "ac" | sed 's/a/b/ ; s/c/d/'

In place edit: sed -i 's/old/new' myfile.txt

Change found text: 's/{old value}/{new value}/g' sed 's/some_text/new_text/' myfile.txt

sed 's/string1/string2/g'	# Replace string1 with string2 sed 's/\(.*\)1/\12/g'		# Modify anystring1 to anystring2 sed '/ *#/d; /^ *$/d'		# Remove comments and blank lines sed ':a; /\\$/N; s/\\\n//; ta'	# Concatenate lines with trailing \ sed 's/[ \t]*$//'		# Remove trailing spaces from lines sed 's/\([\\`\\"$\\\\]\)/\\\1/g'		# Escape shell metacharacters active within double quotes seq 10 | sed "s/^/     /; s/ *\(.\{7,\}\)/\1/"	# Right align numbers sed -n '1000p;1000q '	# Print 1000th line sed -n '10,20p;20q '	# Print lines 10 to 20 sed -n 's/.* \(.*\)<\/title>.*/\1/ip;T;q '
 * 1) Extract title from HTML web page

Remove last occurrence: echo "/dir/" | rev | sed 's#/##' | rev   # /dir rev inputfile | sed 's/ /-/' | rev

Change ASCII 00 character: (using octal value) sed -i "s/\o00/ /g" filename # change 00 to space sed -i "s/\o00/\\n /g" filename # change 00 to new line

Change copyrights in several files: sed -i.BAK -e '/Copyright.*Fusion/s/-20[0-9][0-9]//;/Copyright.*Fusion/s/\(20[0-9][0-9]\)/\1-2013/' `ls *.c`

References:
 * Howto delete empty lines using sed command under Linux / UNIX

sed one-liners
[http://www.catonmat.net/blog/wp-content/uploads/2008/09/sed1line.txt sed one-liners (.txt)


 * [Famous Sed One-Liners Explained, Part I - good coders code, great reuse


 * Famous Sed One-Liners Explained, Part II - good coders code, great reuse

Crazy
Remove the first two numbers from itunes songs: ("02 Rolling in the Deep.mp3" -> "Rolling in the Deep.mp3") ls | awk '{print "mv \"" $0 "\" \"" $0 "\""}' | grep "^mv \"\([0-9]\+\)" | sed 's/"[0-9]\{1,2\} /"/2' | sh

Convert Line Ending
sed 's/^M$//' windows.txt > unix.txt sed 's/\r$//' windows.txt > unix.txt