korn shell notes
----------------------------------------------------------------------
Commands:
----------------------------------------------------------------------
# - comment line
> - output to a file
>> - append to a file
< - input from a file
<<! - redirect from inside a shell script until next !
VAR=value - assigns value to shell variable
echo "$VAR did something" - $ in front of variable name prints value
----------------------------------------------------------------------
Special Variables:
----------------------------------------------------------------------
$$ - current process id PID
$* - all command line arguments
$# - number of command line arguments
$0 - shell program name
$3 - third argument on command line
$? - return code of last command 0 is usually successful
----------------------------------------------------------------------
Control Structures:
----------------------------------------------------------------------
end of if is if spelled backwards
elif is else if
----------------------------------------------------------------------
if [ $VAR = XXX ]
then
echo "do something if true"
elif [ -f $FILE -a -r $FILE ]
echo "$FILE is a file and is readable"
else
echo "do something else if not true
fi
----------------------------------------------------------------------
if VAR is null then the above if gives syntax error
if [ "$VAR"x = "XXX"x ] will fix problem
----------------------------------------------------------------------
read FILE_NAME - does input in variable
TODAY=`date +"%y/%m/%d %A"` - output date command into variable TODAY
----------------------------------------------------------------------
end of case is case spelled backwards
options on case statements do pattern matching
----------------------------------------------------------------------
case $FILE in
/DW/*)
echo "is a program"
;;
/xfer*)
echo "is data"
;;
*)
echo "* is always true"
;;
esac
----------------------------------------------------------------------
while [ -f $FILE ]
do
echo "something if FILE is a UNIX file"
break - will break out of loop
done
----------------------------------------------------------------------
pipe from command
----------------------------------------------------------------------
ls dw* |
while read FILE_NAME
do
grep mailx $FILE_NAME
if [ $? -eq 0 ]
then
echo "$FILE_NAME has mailx in it"
rm $FILE_NAME
fi
done
----------------------------------------------------------------------
redirect input from file
----------------------------------------------------------------------
while read FILE
do
echo $FILE
done <inputfile
----------------------------------------------------------------------
for FILE in $*
do
# FILE values come from command line arguments
rm $FILE
done
----------------------------------------------------------------------
true false statements
----------------------------------------------------------------------
spaces around [ and ] are absolutely neccessary
also spaces around <>=!= are absolutely neccessary
----------------------------------------------------------------------
test -d /dirname is same as [ -d /dirname ]
-f checks for file
-d checks for dir
-r is file readable
-x is file executable
-eq numeric test
-gt numeric test
-ge numeric test
-lt numeric test
-le numeric test
-a and
-o or
!= not equal
<> also not equal
----------------------------------------------------------------------
Example:
----------------------------------------------------------------------
if [ $# -lt 3 ]
then
echo "Usage: $0 sys dir file"
exit 3
fi
----------------------------------------------------------------------
UNIX commands:
----------------------------------------------------------------------
lp -d cc099_hp4si28 filename - prints file
cat file1 file2 file3 >newfile - combines file1,2 and 3
tail -3 file1 - displays last 3 lines of file1
head -4 file1 - displays first 4 lines of file1
cp file1 file2 - copies file1 to file2
cp file1 dir - copies file1 into dir
mv file1 file2 - renames file1 to file2
mv file1 file2 file3 dir - moves files 1 thru 3 into dir
wc -c file1 - counts chars in file1
wc -l file1 - counts lines in file1
ls -l & - runs ls -l in background
ls -l | mailx -s"subject" userid - mails results of ls command
mailx -s"testing" kyennara - mails message to kyennara (^d stops)
df -k - disk free space in 1K blocks
bdf - nicer version of abpve
du -s -k /DW - disk usage summary of files in /DW in 1K blocks
grep regexpression file1 file2 - will print lines that match exp
grep -v regexpression file1 - will print lines that do not match exp
grep -i regexpression file1 - will ignore case
fgrep - fast grep
egrep - extended grep
egrep -f regexpfile file1 - will do multiple regexp from regexpfile
the expressions are line1 or line2 or line3
date | cut -c4-7 - cut columns 5 thru 8 month from date command
date | cut -d" " -f4 - cut field 4 time from date command
TABLE=`echo "$TABLE " | cut -c1-10`
- will force TABLE to be 10 chars long
grep $LOGNAME /etc/passwd | cut -d":" -f3 - cuts UNIX group id
pr -t -s -m file1 file2 - will print file1 and file2 side by side
basename $FILE_NAME - will print just the file name not the path
dirname $FILE_NAME - will print the dir the file is in
hostname - prints the UNIX machine name
set - $LINE - will parse LINE into $1 $2 $3 etc
ROWS_NOT_LOADED=`expr $ROWS_NOT_LOADED + $ROWS` - will do math
exit 3 - will exit with return code of 3
who - list users
who -a - lists all fields
ps -ef - lists process table
ps -ef | grep $LOGNAME - lists my process table
ps -f - lists my process table (better method)
ps -ef | grep bawillia - lists Bruce's process table
ps -fu bawillia - lists Bruce's process table (better method)
----------------------------------------------------------------------
find all the files with yy and not yyyy
if grep.list has yy[^y]
----------------------------------------------------------------------
find . -type f -exec egrep -n -f grep.list {} /dev/null \;
USER=kduke
ps -fu $USER | grep -v PID |
while read LINE
do
set - $LINE
PID=$2
# will kill all $USER processes
kill $PID
done
----------------------------------------------------------------------
Notes:
----------------------------------------------------------------------
Normally ksh is setup to do vi commands on history.
ESC puts you in vi mode.
Arrow keys will not work.
Use h,j,k,l for left,down,up and right.
/^vi will find your last vi command.
dd will create a blank line then hit return to get out of vi mode.
----------------------------------------------------------------------
Translate to your Language
Labels
- BI
- Big Data
- BO
- BO Universe Context
- BusinessObjects Context
- BusinessObjects Universe Context
- Cognos
- Command Line DataStage Job Export
- DataStage
- DataStage Command Line Compile
- DataStage Job Compile in command line
- DataStage SCD
- DataStage Server JobCompile Script
- DB
- DW
- DW-SCD
- Optimizing BO Universe and Reports
- Optimizing Business Objects Universe and Reports
- Other
- Q&A
- SAP BO
- SCD
Disclaimer Statement
Total Pageviews
47,424
Category
- BI
- Big Data
- BO
- BO Universe Context
- BusinessObjects Context
- BusinessObjects Universe Context
- Cognos
- Command Line DataStage Job Export
- DataStage
- DataStage Command Line Compile
- DataStage Job Compile in command line
- DataStage SCD
- DataStage Server JobCompile Script
- DB
- DW
- DW-SCD
- Optimizing BO Universe and Reports
- Optimizing Business Objects Universe and Reports
- Other
- Q&A
- SAP BO
- SCD
Track
Follow us on FaceBook
About
Powered by Blogger.
Category
- BI
- Big Data
- BO
- BO Universe Context
- BusinessObjects Context
- BusinessObjects Universe Context
- Cognos
- Command Line DataStage Job Export
- DataStage
- DataStage Command Line Compile
- DataStage Job Compile in command line
- DataStage SCD
- DataStage Server JobCompile Script
- DB
- DW
- DW-SCD
- Optimizing BO Universe and Reports
- Optimizing Business Objects Universe and Reports
- Other
- Q&A
- SAP BO
- SCD
Contributors
Blog Archive
-
▼
2012
-
▼
December
- Datastage Universe Quick Refrence
- Conformed Dimensions with example
- BusinessObjects - list of values (LOV)
- What is ETL Mapping Document ?A Real Time Example
- Types Database Schemas
- Types Database Schemas
- Data Warehousing Objects
- Data Warehousing Objects
- Unix Vi Quick Reference
- Unix Vi Quick Reference
- PERL Quick References
- PERL Quick References
- Basic korn shell notes
- Basic korn shell notes
- Normalization...
- Normalization..
- What is Factless Fact Table?
- What is Factless Fact Table ?
- Fact Table Loading Types
- Fact Table Loading Types
- Data Warehouse "Datastage " Staging Area
- Data Warehouse Loading Techniques
- Data Warehouse Loading Techniques
- Why do we need a Data Warehouse Staging Area?
- Why do we need a Data Warehouse Staging Area?
- Datastage Error and reject record Handling simplified
- Datastage Error and reject record Handling simplified
- Traditional BI VS In-Memory QlikView
- Traditional BI VS In-Memory QlikView
- Adding a key field to an existing “Hash” file (con...
- Adding a key field to an existing “Hash” file (con...
- Use of Default or Dummy row in dimension table
- Use of Default or Dummy row in dimension table
- Data Profiling and its importance
- Data Profiling and its importance
- Materialized View
- Materialized View
- Slowly Changing Dimensions
- creating a unique counter in DataStage jobs
- Performance Analysis of Various stages in DataStag
- Performance Analysis of Various stages in DataStag
- creating a unique counter in DataStage job
- creating a unique counter in DataStage job
-
▼
December
Popular Posts
-
Netezza dosen't have any isnumeric check function, so in order to find out whether the column has non-numeric, use the following logic n...
-
If you have table like below GROUP_NAME GROUP_ID PASS_FAIL COUNT GROUP1 5 FAIL 382 GROUP...
-
@echo off :: ----------------------------------------------------------------- :: DataStageExport.bat :: -----------------------------------...
-
The error and reject capturing is one of the best practices that I recommend to all developers, let me explain in a very simple way Rejec...
-
Migrate Universe from one database to another · First backup the original universe in case if something go wrong · Launch ...
-
I have explained the importance of Nosql in my previous post, today I am going to explain about Newsql What is NewSQL ? As you...
-
· Types of Stages in DS? Explain with Examples · What are active stages and passive stages? · Can you filter data...
-
In data warehousing, a conformed dimension is a dimension that has the same meaning to every fact table in the structure. Conformed dim...
-
Source :-dwh-ejtl.blogspot.com Q1) Tell me what exactly, what was your role? A1) I worked as ETL Developer. I was also involved in requireme...
-
What is Big Data? Big data is data that exceeds the processing capacity of traditional database systems. The data is too big, moves too fast...
Wednesday, December 26, 2012
Basic korn shell notes
by Unknown |
in Other
at 8:12 PM
Related Posts
-
Netezza ISNUMERIC Data Check Logic
-
How to do PIVOT in netezza SQL
-
Datastage DSX Files Export Script
-
Datastage Error and reject record Handling simplified
-
SAP BO Universe and Report Migration Part 1
-
What is NewSQL
-
Ton of Data Warehousing and Datastage Interview Questions
-
Conformed Dimensions with example
-
Informatica Job Interview Question & Answers
-
Big Data and Hadoop Questions and Answers
0 comments: