Monday, September 17, 2012

How could you find out all the table names having a specific column name in Oracle?

SELECT TABLE_NAME
FROM ALL_TAB_COLUMNS
WHERE COLUMN_NAME = '<ColumnName>';

SELECT TABLE_NAME
FROM USER_TAB_COLUMNS
WHERE COLUMN_NAME = '<ColumnName>';

SELECT TABLE_NAME
FROM DBA_TAB_COLUMNS
WHERE COLUMN_NAME = '<ColumnName>';

- USER_TAB_COLS for tables owned by the current user and ALL_TAB_COLS or DBA_TAB_COLS for tables owned by all users.

How can you get the First/Top N rows in Oracle?

select *
from <TableName>
where rownum <= n;

Saturday, September 15, 2012

How do you run shell commands transparently within Perl?

#!/usr/bin/perl
use Shell;

my $sh = Shell->new;
print $sh->ls(-l);

or

#!/usr/bin/perl

use Shell qw(ls who);
@fileList = ls ("-l");
@userList = who ("-m");
print @fileList;
print @userList;

How can you receive the output of an external command using open( ) in Perl?

#!C:/Perl/bin/perl -w
use strict;
open (PS, "dir/b |") || die "$!\n";
while ( <PS> )
{
   print "$_\n";
}
close (PS) or die $!;

Thursday, September 13, 2012

Write a batch file to kill frozen programs.

@echo off
taskkill /f /fi “status eq not responding”
exit

- Copy the above 3 lines to Notepad and save the file as "killall.bat".
- On click, it kills all the programs that do not respond.

How do you remove duplicate lines in a file in UNIX without changing order of contents?

awk '!x[$0]++' <FileName> > <New FileName>

How do you create a pseudo drive or map a local folder to a pseudo drive in MS Windows?

Suppose, we want a folder (e.g. AutoDrive) to act as a pseudo drive. Now assume "Z:" to be used as Drive Letter, do either of the followings:

Click Start, choose Run and type:
SUBST Z: C:\AutoDrive
then click OK.
or
type "SUBST Z: C:\AutoDrive" at the command prompt without quotes.

Again, to remove the substituted "Z:" drive, follow either of the ways mentioned below:

click Start, choose Run and type:
SUBST Z: /d
or
type "SUBST Z: /d" at the command prompt without quotes.

Wednesday, September 5, 2012

How can you get basename of a Perl script on any OS using regular expression?

$me = $0;

if ( $^O eq 'MSWin32' )
{
         $me=~s{.*\\}{};
         print "Usage :  $me <file>!\n"
}
else
{
         $me=~s{.*/}{};
         print "Usage :  $me <file>!\n"
}

Or

my $command = $0;
$command =~ s#^.*/##;

Or

( my $me = $0 ) =~ s{.*(\\|/)}{};

Tuesday, September 4, 2012

How do you run the last command without the last argument?

use "!:-"

For example, if the following is the last command

sort -k2 <FileName>

then

!:- <New FileName>

is the same as

sort -k2 <New FileName>

How do you insert the result of a command into VI?

!!<COMMAND>

- will insert the result of the command into vi at the current position of the cursor.