Make your own free website on Tripod.com

# Deleting Duplicate Lines and ignorning comminting lines and deleting blank lines

grep -v '^#' t.p|grep -v '^\['|sed '/^[ ]*$/d'

 

# Deleting Trailing Spaces and tabs

sed 's/[ \t]*$//' <filename> > <newfilename>

$ sed '/^[ ]*$/d' t.tmp |sed 's/[ ]*$//' > t1.tmp

 

Deleting trailing space and tabls:

in vi

1,$s/[<space><tab>]*$//

 

(To Delete blank lines and delete Trailing spaces and tabs)

 

# Removing ^M

Ctr-v+ctr-m = ^M

dos2unix file1.txt file2.txt

 

# UpperFile Names to LowerFile Names

a) Here's a script that will lower case any file, to lowercase every file in a directory tree.

find /usr/braindead/NTFILES -exec lcase {} \;

b) for i in nt*.txt

do

tr '[A-Z]' '[a-z]' $i > $i.tr

done

# Edit all pages of the string

vi `grep -l anystring *`

 

# Attach documents to Mailx utility:

 

#!/bin/ksh

#

SUBJECT="Example"

TO=svaliveru@ea.com

SPOOL=/tmp/fifo$$.txt

sqlplus -s majestic/majestic > $SPOOL << EOF

set echo off feedback off verify off

set serveroutput on lines 132 pages 0 head off escape on

select table_name from all_tables;

quit

EOF

unix2dos $SPOOL $SPOOL 2>/dev/null

/usr/bin/mailx -s "${SUBJECT}" ${TO} << EOF

~< !echo

~< !uuencode $SPOOL `basename $SPOOL`

~< !echo

EOF

 

# Memory consumed by individual process

a) ps -e -o rss -o pid -o ppid -o comm | sort -rn | less

b) /usr/ucb/ps -auxwww

c) ipcs -mb

 

# Recursive Grep

find . -type f -print | xargs grep <string>

 

# Uncompess and Un tar in single command

gzip -cd <filename>.tar.gz | tar xvf -

cat mytarball.tar.Z|uncompress -|tar -xvf -

 

 

# a)Files older than a specified file :

$ find . -name '*.sql" ! -newer <filename> -print

b) Remove files older than a specified file:

$ find . -name '*.sql" ! -newer <filename> -exec rm -f {} \;

 

c)The following command suppress the file not accessible etc junk messages..

$ find / -name "filename" -print 2>/dev/null

d) Following Command gets all the files greater than 1 block.(1block=512 Bytes(1/2 KB))

$ find . -type f -size +1 -print

# Deleting files containing some text

rm `ls -al | grep str | awk '{if ($9 !~ /^str/) {print $9}'`

# Block Size in unix by

prtvtoc command needs to run as root..

# Hardware configuration of the server

/usr/platform/sun4u/sbin/prtdiag

# For memory

prtconf | grep -i "Memory size"

# For System Details

dmesg

# To view Non -printable characters in VI editor ,use :set list

# sh -x filename.sh ( gives all the variables used in the script)

# Moving contents one level up

$ mv docs/* .

ls -1|awk '{print "mv "$1"/docs/* "$1"/."}' > temp.sh

# tr "\011" " " < dirty.txt | tr -s " " >| clean.txt

# tar cBpf - . | (cd ..; tar xpBvf -)

# copy recursively

a) cp -r /src /dest

b) (cd /src;tar cf - *) | (cd /dest;tar xpf -)

where /src is the source directory and /dest is the destination directory.
This is better than using a recursive copy because symbolic links and file permissions are kept.

# clever way to archive

tar cvf - `find . -name "*.sh" -print` >/tmp/dumpfile.tar

tar xvf - </tmp/dumpfile.tar

# Get 10 characters after the "host=" string.

awk '{ print substr($0,index($0,"host=")+5,index($0,"host=")+10) }' listerner.log

# Softlinks for all the directories

ls -1|awk '{print "ln -s "$1" str1"substr($1,4)}' > s.sh

 

 

# Exact Pattern Search.

grep -w "pattern" fileName for exact pattern

 

# Find %CPU and PID and user running the processs for all processes..

Note: "top" command gives only top %CPU consumption processes

ps -edf -o pcpu,pid,user,args

 

# No browser no problem..

$ telnet majdev 80

Trying 10.14.136.112...

Connected to majdev.

Escape character is '^]'.

GET / HTTP/1.0 ( or GET /utils/prod/home.htm HTTP/1.0 )

Host: majestic.ea.com [two returns follow]

 

# truss -eaf -o out.log sqlplus

# OLDER THAN SEVEN DAYS

find . -name "*.log" ! -mtime -7 -exec ls -ltr {}\;

find /opt/oracle/export \( -name "*.dmp" -o -name "*.log" \) ! -mtime -7 -exec rm } \;

# pfiles <pid> ( for File Description)

# dirname '/opt/oracle/rman/script/filename.sh'

yeilds the directory name where the file resides

# Ever need to edit all the files in a directory containing a particular string?
Use the -l option of grep to build a list of filenames, and use backquoting to ship that list to vi:
$ vi `grep -l anystring *`

# usage of should come in first few lines of shell trap 'rm -f ./_tmp.??.tmp; exit' 0 1 2 3 15

# Check Filesystem space

df -k|grep -i eacom | awk '{ print $6 " " $2/1024/1024 }'|sort

du -sk /home/oracle/* |sort -n

 

# check to see if the latest file is locked by any process or not

#! /bin/sh

ls -tlr|tail -1|awk ' { print $9 }'|

while read file

do

if pids=`fuser "$file" 2>/dev/null` && [ -z "$pids" ]

then

# fuser returned normally and produced no output

echo $file "is not used by any process"

else

echo $file "is USED by any process"

fi

done

 

My Single line Unix command

 

grep -v '^#' t.p|grep -v '^\['|sed '/^[ ]*$/d'|awk -F"=" '{ printf "\n"$1"_def="$2"\necho \""$1"(Def $"$1"_def):\c\"\nread "$1"\n[ \"${"$1"}\" = \"\" ] && "$1"=$"$1"_def\n"}'

 

cat mytarball.tar.Z|uncompress -|tar -xvf -

 

Summing in one command

grep "Characters Deleted: " del_char*|awk -f: '{sum +=$3; } END { print sum; }'

 

List Directories for the active database :

 

find /eacom/usr0* -type d -print|awk '{print "mkdir -p " $1 }' > /var/tmp/usrprd.dir

 

find /eacom/usr0* -type d -print|awk '{print "mkdir -p " gsub("usr","usrtst",$1) }'

 

cpio -icdmv < 9204_solaris_release.cpio

 

How do I find the process ID of a program with a particular name

ps -ef -uoracle | awk '/LISTENER/ && !/awk/ {print $2}'

Gets you the listener process id..

 

good ps formatting showing percent cpu first.

ps -edf -o pcpu,pid,user,args

List only directories..

find /eacom/lstandby -type d -print|awk '{print "mkdir -p " $1}'

 

# print the line immediately before a regexp, but not the line

# containing the regexp

sed -n '/regexp/{g;1!p;};h'

 

# print the line immediately after a regexp, but not the line

# containing the regexp

sed -n '/regexp/{n;p;}'

 

To Get paragraph

sed -n '/and where it came/,/for all people/p' myfile

Block from BEGIN to END

sed -n -e '/BEGIN/,/END/p' /my/test/file | more

sed -n -e '/oracle/,//p' m.txt from file containing oracle to end of the file

 

Replace only in a block : starting with blank line and ending with a line

1. sed -e '/BEGIN/,/END/ s/hills/mountains/g' myfile.txt

2. sed -e '/^$/,/^END/s/hills/mountains/g' myfile3.txt

will swap 'hills' for 'mountains', but only on blocks of text beginning with a blank line, and ending with a line beginning with the three characters 'END', inclusive.

This example will remove comments from the beginning of the file until it finds the keyword "start:"

sed -e '1,/start/ s/#.*//'

grep -v </tmp/b --> sed -n '/match/ !p' </tmp/b

In sed --> "!p" is similar to "d," while "!d" is similar to "p

 

Reverse the files lines 1100 to 1001

sed -e '1!G;h;$!d' forward.txt > backward.txt

 

Trace file tkprof:

find . \( -newer usrprd_lgwr_25875.trc -a -name "usrprd_p*.trc" \) |awk '{ print "tkprof " $1 " out/"$1 ".out explain= \\\"/ as sysdba \\\"" }'

 

TRAP:

trap 'stty echo;echo "Exiting from setup.sh due to ctl-c being pressed";exit'

 

How Can we tell  Solaris OS is running 32-bit or 64-bit?

isainfo -b

Or

Use the isalist command to determine whether the machine is running

the 32-bit or 64-bit operating system. If you are running the 64-bit

operating system on an UltraSPARC machine, then isalist

will list sparcv9 first

 

To get supported list of TCP parameters:

 

ndd -get /dev/tcp ?

To get the value of a parameter:

ndd -get /dev/tcp param_name

To set the value of a parameter:

ndd -set /dev/tcp param_name param_value

 

Examples:

1) getting the TCP keepalive timeout value

ndd -get /dev/tcp tcp_keepalive_interval

2) setting the time_wait interval

ndd -set /dev/tcp tcp_time_wait_interval 60000

 

AWK QUICK COLUMNS

Most of the time when you use awk from the command line,
you're doing something simple like this:

ps -ef | grep netscape | awk '{print $2}'

To save typing, use this script when you only want to
use awk to print out one or more columns:

------------------- CUT HERE ---------------------------
#!/bin/ksh
# awkc - print out one or more columns

p=\$$( echo $1 | sed 's/,/,\$/g' )
shift
eval "awk '{ print $p }'" $*

# eof
------------------- CUT HERE ---------------------------
Example:

Now you can do things like:
ps -ef | awkc 2,1
or
awkc 1,2,3 /var/adm/messages*

 

Copy Directories Trees( From one machine to antoher):

Excluding files and their contents.

 

machine_a # find /mydir -type d -print|awk '{print "mkdir -p " $1}' > /tmp/dir.awk

Copy the dir.find to another machine.

machine_b# chmod +x /tmp/dir.awk;/tmp/dir.awk

Or

machine_a # cd /mydir
machine_a # find . -type d -depth -print | cpio -o -O /tmp/dir.cpio

Copy the dir.cpio to another machine.

machine_b # mkdir /mydir ; cd /mydir
machine_b # cat /tmp/dir.cpio | cpio -id

Recurisive COPY:


cd srcdir

tar cf - . | ( cd /dest; tar xfp - )

or

cd srcdir

find . -depth -print | cpio -pdm dest

 

Or

cd src

cp -rp src dest

Appending Text At Both Ends:

worthless

:/^\(.*\)/s//DONTFEEL \1 ANYTIME/

DONTSAY worthless ANYTIME