Wednesday, June 22, 2011

BASH shell only - brace expansion

You might have used brace expansion if you have tried this very popular way of backing up files - 
cp filename{,.bk}

The command above will copy filename to filename.bk. It saves you from writing the filename again. 
This neat stuff is not compatible with korn shell.
Some other examples to reinforce how this works.

echo John{Doe,Smith}
  JohnDoe JohnSmith
echo {John,Jane}{Doe,Smith}
  JohnDoe JohnSmith JaneDoe JaneSmith
  

Note the lack of space after comma.

Wednesday, May 11, 2011

vi or sed - Delete till end of line from pattern

Here's the regex that will match everything from the pattern until a newline is found.

Say you want to remove everything after "here" from this sample file.

code here    where?
code here   right here!
code here         look every where.
Used regex
s/here.*//
Explanation:
.*  
dot matches any character including spaces, numbers, alphabets but not new line.
asterisk matches any number of occurrences of a character

s/here.*/meow/ will result in

code meow
code meow
code meow

Monday, May 9, 2011

Shell script for multiple SED edits

Following shell script
1.    Reads the names of the files to be edited from the file "filelist".
2.    Executes two sed statements on each of those files and
3.    Overwrites the original file. 


#!/usr/bin
while read line
do
sed 's/0512/0505/g' $line > temp
sed 's/05\/13/05\/06/g' temp > $line
done < filelist 

Saturday, April 2, 2011

Creating SQL statement for a Target Definition

I learned two things -
1. Don't blindly believe when people say it can't be done.
2. Informatica lets you create SQL statement to create target table.

I've been working to load this massive VSAM file with more than 1500 fields. Creating the source definition from the COBOL copybook was simple but creating ORACLE table manually for these many fields dampened my spirits.

I asked one of the more senior guys around here if he knew how to do it since he has been working on the same project with me. He said it wasn't possible and that I needed to do it manually.

I came back crushed and started reading Informatica Manual to delay my nemesis (so dramatic but seriously 1500 fields!).

It's then I learned that once the target definition has been created, Target Designer lets you "Generate/Execute SQL" for the target. BINGO! I was done in 2 minutes.

PS - To create target definition, I just dragged and dropped the source definition to target designer.

Sunday, February 20, 2011

Automator - Get folder name using Shell Script


I wanted to move a folder from Movies to Music and rename both the folder and the videos.

Challenge was to 
1) Pass output of previous action to shell script.
2) Get the folder name.

#1 Passing output of previous action to shell script
Once you drag and drop Utilities/Run Shell Script action and change drop down "Pass Input" to "as arguments", it becomes evident that the values are passed in the usual way command line variables are passed to a shell script in Unix. i.e. in $@

If you see in the automator workflow above, I'm getting all the file names in the folder as $@ in my script. You might know that we can access the contents of $@ as $1, $2 etc and $# gives the total number of variables, in this case number of files.

Here's how I went over the list of files and renamed them all.

#Say for example $@ has "/Users/ruchi/Movies/Snowboarding 2010/videofile1.AVI /Users/ruchi/Movies/Snowboarding 2010/videofile2.AVI"
while [ ! -z "$1" ]
do
mv "$1" "`echo "$1" | sed 's/\[[aA-zZ,.]*\] [aA-zZ, ]* - [0-9][0-9] - //g'`"
shift
done

#2 Getting the folder name
This is more of a hack. I already had file names with path in #1, I checked the depth of my the folder from home (/Users/ruchi/) and used awk to get the folder name from a file name.

#for example let's say $1 has /Users/ruchi/Movies/Snowboarding 2010/videofile1.AVI
foldername=`echo "$1" | awk -F/ '{print $5}'` # That's right, not $4 but $5 due to leading "/"
echo $foldername #output: Snowboarding 2010

Here's another tutorial on how to pass variables to shell script.

Friday, February 4, 2011

Text Wrapping is Working

Many thanks to cimg's tutorial on dynamic cell height, text wrapping is working. If you want to keep the default font and size for the not-so-long data cells, keep the height fixed as 44.0f and use "initWithStyle:UITableViewCellStyleDefault" formatting on those cells.

Thursday, February 3, 2011

iOS or Cocoa - lookup that method

I was feeling lost with what the parameters for a method and found the way to look it up without leaving xcode. Just CMD+double click the method.

Here's the link to thank for.
CGRectMake parameters ? « cocos2d for iPhone

And am writing this post using blogger bookmarklet (chrome addon) called "blog this". It lets you blog any webpage from that page.