Useful Code Snippets

Uppercase to Lowercase

tr '[:upper:]' '[:lower:]' < inputFile > outputFile

REPLACING TABS WITH SPACES (see also blog post)

perl -p -e 's/\t/    /g' input.c > output.c

CONVERTING BULK IMAGES FROM JPG TO PNG

#!/bin/bash
for img in *.jpg
do
    filename=$(basename "$img")
    extension="${filename##*.}"
    filename="${filename%.*}"
    echo $filename
    convert "$img" "$filename.png"
done

REMOVING NEWLINES (and replacing with spaces)

tr '\n' ' ' < inputFile

REMOVING // comments from a c program (to standard output)

sed 's://.*$::g' file.c

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s