Wednesday, November 24, 2010

Adding one month (30-31 days) in UNIX SOLARIS


#! /usr/bin/ksh
d=`date +%d`
m=`date +%m`
y=`date +%Y`
if [ $m%2 -eq 0 ]
then
d1=`expr $d + 30`
d=expr $d1 - 30`
else
d1=`expr $d + 31`
d=expr $d1 - 31`
fi
if [ $m -eq 12 ]
then
y=`expr $y + 1`
m=0
fi
m=`expr $m + 1`
if [ $m -lt 10 ]
then
m=0$m
fi
echo "$y-$m-$d"
exit 0

Monday, June 14, 2010

sort a delimited file on the basis of a column

sort -t":" -k3 filename.txt

(The above will sort a file filename.txt which is ":" delimited on the basis of third column.)

Tuesday, May 4, 2010

Print every 6th line of a file ..

The below awk command will print every 6th line of a file test.txt starting from line number one.

awk '{if(NR%6==1) print $0}' test.txt

(Note: Print every nth line using awk.)

Sunday, February 14, 2010

Sed Options

use sed when ....

# insert a blank line above every line which matches "regex"
 sed '/regex/{x;p;x;}' OR  sed '/regex/{x;G;}'

# insert a blank line below every line which matches "regex"
 sed '/regex/G'

# insert a blank line above and below every line which matches "regex"
 sed '/regex/{x;p;x;G;}'

# remove the header of a file
sed '/1,1d' filename

Saturday, January 23, 2010

Basic UNIX Questions

All questions are for command line use in UNIX environments. 

Q: How do you display your running kernel version? (Solaris, AIX, Linux)
A: Linux # uname –r , Solaris # showrev

Q: Which command do you use to display a table of running processes? (Solaris, AIX, Linux)
A: Linux # ps –ef and top , Solaris # prstat 

Q: Which file do you modify to configure a domain name resolver? (Solaris, AIX, Linux)
A: Linux # /etc/resolv.conf , Solaris # /etc/resolv.conf

Q: Which file contains a list of locally defined hostnames and corresponding IP addresses? (Solaris, AIX, Linux)
A: Linux # /etc/hosts , Solaris # /etc/hosts and linked file /etc/inet/hosts 

Q: How do you display a routing table? (Solaris, AIX, Linux)
A: Linux # ip route show or #netstat –nr or #route –n and Solaris # netstat –nr and #route -n

Q: Which command would you use to view partitions and their sizes on Solaris?
A: # df -kh

Q: Which OpenBoot command would you use to print/view OpenBoot environment variables on a SUN server?
A: #printenv

Q: What does "ypwhich" command do? (Solaris, AIX, Linux)
A: # Will display NIS server to which client is connected to and which NIS Server is master for particular map specified with this command

Q: which command would you use to create an OS user on Solaris and Linux?
A: Linux # useradd and Solaris #useradd

Q: Which file contains passwords for local users on Solaris, Linux and on AIX?
A: Linux #/etc/shadow and Solaris # /etc/shadow

Q: Which command would you use to list partitions on Linux?
A: Linux # mount –l or # df -kh

Q: Which command/commands would you use to manage installed packages on RedHat Linux?
A: Linux # rpm 

Q: What is the default port for SSH server? 
A: 22

Q: Which command/commands would you use to manage installed packages on Solaris?
A: #pkginfo #pkgrm # pkgadd #pkgchk

Q: What command would you use to install an OS patch on Solaris?
A: #showrev –p and #patchadd -p

Q: Which Veritas command would you use to display a list of Veritas volumes?
A: # vxprint

Q: Which Veritas command would you use to display a list of disks on a system?
A: # vxdx list

Q: What is the main system configuration utility in AIX?
A: 

Q: Which file has a list of filesystems to be mounted at boot time on Solaris, Linux and AIX?
A: Linux # /etc/fstab and Solaris #/etc/vfstab

how to get patterns of file 1 "a" in file 2 "b"



#! /usr/bin/sh

while read line
do
grep $line b >>final
done<a

how to get yesterday date in unix



YEST=`TZ="GMT+24" date +'%m/%d/%Y'`; echo $YEST

Print next 7 lines of the file sample2 after pattern match from file sample1:



for i in `cat sample1`;do sed -n "/$i/{p;n;p;n;p;n;p;n;p;n;p;n;p;n;G;p;}" sample2 ; done

 

Blogger news

Blogroll