BASH File Manipulation

HOWTO: Show The Resolution / DPI Of An Image
identify -verbose photo.jpg |grep 'Resolution' Resolution: 72x72

HOWTO: Remove Blank Lines From A Text File
sed -i '/^$/d' file.txt or cat myfile.txt |sed '/^$/d'

Add A Zero To The Beginning Of A Filename
$ renamexm -t -v -s/^/0/r [0-9] *.mp3 rename 1 Subdivisions.mp3  => 01 Subdivisions.mp3  : tested rename 2 The Analog Kid.mp3 => 02 The Analog Kid.mp3 : tested rename 3 Chemistry.mp3     => 03 Chemistry.mp3     : tested rename 4 Digital Man.mp3   => 04 Digital Man.mp3   : tested rename 5 The Weapon.mp3    => 05 The Weapon.mp3    : tested rename 6 New World Man.mp3 => 06 New World Man.mp3 : tested rename 7 Losing It.mp3     => 07 Losing It.mp3     : tested rename 8 Countdown.mp3     => 08 Countdown.mp3     : tested

Convert Tabs To Spaces In a File
expand file.txt

Delete Characters On Just The First Line
This deletes all the quotation (") characters on just the first line of a CSV file...

sed '1s/"//g' /tmp/oldfile.csv > /tmp/newfile.csv

http://sed.sourceforge.net/sed1line.txt

HOWTO: Mass File Rename Deleting Part Of Name
e.g.

Scooby_Doo_Mystery_Incorporated_S02E25 Through The Curtain 720p x264.mp4 => Scooby_Doo_Mystery_Incorporated_S02E25.mp4

Do...

renamexm -v -s/" .*.mp4"/".mp4"/e *.mp4

HOWTO: Rename All Files Add File Extension
for f in *; do mv "$f" "$f.jpg"; done

HOWTO: Find Out Length Of Longest Line In A File
wc -L file

HOWTO: Find Line Exceeding N Characters
grep '.\{N\}' file

HOWTO: Trim Leading White Space
sed 's/^ *//g'

e.g.

lynx -nolist -dump http://wiki.indie-it.com/wiki/Television_Paully |sed -n '/What I Am Currently Watching/,/What I Have Been Watching/p' |sed 's/^ *//g' |egrep '^[0-9]'

Thanks to Stackoverflow.

HOWTO: Pattern Match Between 2 Lines
I Love Linux ***** BEGIN ***** BASH is awesome BASH is awesome ***** END ***** I Love Linux

sed -n '/BEGIN/,/END/p'

Thanks to Shell Hacks]