It's All About ORACLE

Oracle - The number one Database Management System. Hope this Blog will teach a lot about oracle.

grep command in Solaris


grep with ls command:
======================
  • Finding files whose last 4 digits are not integer:
bash-3.2# ls -ltr *[!0-9][!0-9][!0-9][!0-9]
-rw-r--r--   1 root     root     8101353 May 21  2012 apache-tomcat-7.0.27.zip
-rw-r--r--   1 root     root     1058049 Jun  5  2012 kanban.war
-r--------   1 root     root          16 May  6 15:01 autoreg_key
-rw-------   1 root     root          72 May  6 15:01 autoreg_config
-rw-r--r--   1 oracle   oinstall       0 May 11 13:25 DGStatusMonitor.lock
  • Finding files whose last 4 digits are integer:
bash-3.2# ls -ltr *[0-9][0-9][0-9][0-9]
-rw-rw----   1 oracle   oinstall  889038 May 10 08:31 net11956
-rw-rw----   1 oracle   oinstall   10417 May 10 08:31 US11956
-rw-rw----   1 oracle   oinstall   22605 May 10 08:31 TCP11956
-rw-rw----   1 oracle   oinstall       0 May 10 08:31 ITCP11956
-rw-rw----   1 oracle   oinstall   15076 May 10 08:31 BEQ11956
-rw-rw----   1 oracle   oinstall   16566 May 10 08:31 TCPS11956
-rw-rw----   1 oracle   oinstall       0 May 10 08:31 SPX11956
-rw-rw----   1 oracle   oinstall       0 May 10 08:31 ISPX11956
-rw-rw----   1 oracle   oinstall       0 May 10 08:31 DEC11956
-rw-rw----   1 oracle   oinstall       0 May 10 08:31 DCE11956
-rw-rw----   1 oracle   oinstall       0 May 10 08:31 LU6211956
-rw-rw----   1 oracle   oinstall       0 May 10 08:31 NMP11956
-rw-rw----   1 oracle   oinstall       0 May 10 08:31 RAW11956
-rw-rw----   1 oracle   oinstall       0 May 10 08:31 VI11956
-rw-rw----   1 oracle   oinstall 1700310 May 10 08:31 net12166
-rw-rw----   1 oracle   oinstall   17738 May 10 08:31 US12166
  • Finding only directories:
bash-3.2# ls -ltr | grep ^d
drwxr-xr-x   2 oracle   oinstall     512 May 11 13:25 dataguard


  • Finding all files whose file name starts with first two digits capital alphabet, then 3rd, 4th digit are numeric.
bash-3.2# ls [A-Z][A-Z][0-9][0-9]*
LU6211956  LU6216111  LU623695   LU627535   US11956    US16111    US3695     US7535     VI11956    VI16111    VI3695     VI7535
LU6212166  LU6216485  LU623905   LU627909   US12166    US16485    US3905     US7909     VI12166    VI16485    VI3905     VI7909
LU6212519  LU6216695  LU624255   LU628119   US12519    US16695    US4255     US8119     VI12519    VI16695    VI4255     VI8119
LU6212729  LU6217925  LU624465   LU629331   US12729    US17925    US4465     US9331     VI12729    VI17925    VI4465     VI9331
LU6215893  LU6218135  LU627317   LU629541   US15893    US18135    US7317     US9541     VI15893    VI18135    VI7317     VI9541
bash-3.2# 


  • Checking for all directories:
bash-3.2# ls -l | grep ^d  
drwxrwxr-x   5 adm      adm          512 May  6 15:03 acct
drwxr-xr-x   4 root     root         512 May  9 22:36 ChargingSystem
drwxrwxrwt   2 root     root         512 May 11 22:41 ChargingSystemLogs
drwxr-xr-x   2 adm      adm          512 Jan 31 19:44 exacct
drwxr-xr-x   2 adm      adm          512 May  9 23:06 log
drwxr-xr-x   2 root     sys          512 Jan 31 19:49 pool
drwxrwxr-x   2 adm      sys          512 Jan 31 19:45 sa
drwxr-xr-x   2 root     sys          512 Jan 31 19:47 sm.bin
drwxr-xr-x   2 root     sys          512 Jan 31 19:44 streams
  • Checking for all files only:
bash-3.2# ls -ltr | grep ^-rw
-rw-rw-rw-   1 root     bin            0 Jun 28  2011 spellhist
-rw-------   1 uucp     bin            0 Jun 28  2011 aculog
-rw-r--r--   1 root     root           0 Jan 31 19:57 vold.log
-rw-r--r--   1 root     root      452949 May  7 02:01 messages.2
-rw-r--r--   1 root     root      329127 May 13 05:17 messages.1
-rw-r--r--   1 root     root        2116 May 20 05:17 messages.0
-rw-r--r--   1 root     root        6145 May 23 10:28 messages
-rw-r--r--   1 root     bin         5208 May 23 17:27 utmpx
-rw-r--r--   1 adm      adm       395064 May 23 18:00 wtmpx
-rw-------   1 root     root       20681 May 23 18:03 sulog
-rw-r--r--   1 root     root         105 May 23 18:48 emc_monitor.log

grep command:
==============
  • Finding all files in a directory having string "running":
bash-3.2# grep -l running *
dg_status_Sat_May_11_13:25:40_2013.log
bash-3.2# 
  • Finding lines in file dg_status_sasa.log where "running" string is present.
bash-3.2# grep running dg_status_sasa.log 
-- dgstatusmonitor running at Sun_May_12_01:29:47_2013 --
-- dgstatusmonitor running at Sun_May_12_13:29:55_2013 --
-- dgstatusmonitor running at Mon_May_20_01:35:45_2013 --
-- dgstatusmonitor running at Mon_May_20_13:35:53_2013 --
-- dgstatusmonitor running at Tue_May_21_01:36:01_2013 --
-- dgstatusmonitor running at Tue_May_21_13:36:09_2013 --
bash-3.2# 
  • Finding lines in file dg_status_sasa.log where "running" string is not present.
bash-3.2# grep -v running dg_status_sasa.log 


  • Check for case insensitive "running" sting also:

bash-3.2# grep -i running dg_status_sasa.log 


  • Checking how many times "running" occured:

bash-3.2# grep -c running saasaa.log 
6
  • Check for line number at which it occurs:
bash-3.2# grep -n running saasaa.log 
5:-- dgstatusmonitor running at Sun_May_12_01:29:47_2013 --
7:-- dgstatusmonitor running at Sun_May_12_13:29:55_2013 -- running
21:running
50:-- dgstatusmonitor running at Mon_May_20_01:35:45_2013 --
52:-- dgstatusmonitor running at Mon_May_20_13:35:53_2013 --
54:-- dgstatusmonitor running at Tue_May_21_01:36:01_2013 --
56:-- dgstatusmonitor running at Tue_May_21_13:36:09_2013 --
  • Make a search for two patterns using extended grep (egrep):
bash-3.2# egrep '(running|DGMGRL)' saasaa.log 
-- dgstatusmonitor running at Sun_May_12_01:29:47_2013 --
-- dgstatusmonitor running at Sun_May_12_13:29:55_2013 -- 
running
Additional information retrieved : DGMGRL for Solaris: Version 10.2.0.5.0 - 64bit Production
Welcome to DGMGRL, type "help" for information.
Additional information retrieved : DGMGRL for Solaris: Version 10.2.0.5.0 - 64bit Production
Additional information retrieved : DGMGRL for Solaris: Version 10.2.0.5.0 - 64bit Production
-- dgstatusmonitor running at Mon_May_20_01:35:45_2013 --
-- dgstatusmonitor running at Mon_May_20_13:35:53_2013 --
-- dgstatusmonitor running at Tue_May_21_01:36:01_2013 --
-- dgstatusmonitor running at Tue_May_21_13:36:09_2013 --

0 comments:

You Might Also Like

Related Posts with Thumbnails

Pages