Latest Blogs

Saturday, September 17, 2022

Linux Shell Script - AWK usage

Title: Linux Shell Script - AWK usage 

Responsibility: Absolutely no responsibility. Use at your own risk.


awk '1' dbv_*.err  > alldf_mylog.txt


grep -E -w 'DBVERIFY - Verification starting|Total Pages Encrypted' alldf_mylog.txt >>  dbv_enc_apply_status.txt



sed 'N;s/\n/ /' dbv_enc_apply_status.txt > mergeeachDBFin1Line.txt


grep -E -w 'Total Pages Encrypted        : 0' mergeeachDBFin1Line.txt >>  onlyzero.txt



--

----grep -Ril "DBVERIFY - Verification starting : FILE = /oradata3/fcubs/PROD_mds.dbf"



grep 'warning\|error\|critical' /var/log/messages



awk 'NR % 6'            # prints all lines except lines 6,12,18...

awk 'NR > 5'            # prints from line 6 onwards (like tail -n +6, or sed '1,5d')

awk '$2 == "foo"'       # prints lines where the second field is "foo"

awk 'NF >= 6'           # prints lines with 6 or more fields

awk '/foo/ && /bar/'    # prints lines that match /foo/ and /bar/, in any order

awk '/foo/ && !/bar/'   # prints lines that match /foo/ but not /bar/

awk '/foo/ || /bar/'    # prints lines that match /foo/ or /bar/ (like grep -e 'foo' -e 'bar')

awk '/foo/,/bar/'       # prints from line matching /foo/ to line matching /bar/, inclusive

awk 'NF'                # prints only nonempty lines (or: do not print empty lines, where NF==0)

awk 'NF--'              # removes last field and prints the line

awk '$0 = NR" "$0'      # prepends line numbers (assignments are valid in conditions)

awk '!a[$0]++'          # suppresses duplicated lines! (figure out how it works)



[oracle@mysqldbwr1 tde1]$ more xyz.txt

1, Bakht

2, Hayat

3, Hasan Khalil

4, None



=====================================

--print only  second field where data is None" 

awk '$2 =="None"' xyz.txt

--print all records


[oracle@mysqldbwr1 tde1]$ awk '$2 =="None"' xyz.txt

4, None


awk '$1 $2' xyz.txt   ???


=====================================

--print all records

awk '$0' xyz.txt


[oracle@mysqldbwr1 tde1]$ awk '$0' xyz.txt

1, Bakht

2, Hayat

3, Hasan Khalil

4, None


=====================================

--print all records

awk '/Hayat/ || /Hasan/' xyz.txt


[oracle@mysqldbwr1 tde1]$ awk '/Hayat/ || /Hasan/' xyz.txt

2, Hayat

3, Hasan Khalil


=====================================

removes last field and prints the line

awk 'NF--' xyz.txt


1,

2,

3, Hasan

4,

Thursday, September 15, 2022

Oracle dbv Verify output Merge and Check encrypted status

Rem: This script is used to merge output of all datafile dbv status and identify encryption status. 

Rem: This execution requires only in 11g R2 and earlier to verify TDE implementation status

Rem: In 12c, data file header contains TDE implementation status

Note: This script is used for testing purpose, the author claims no responsibility of it.


[oracle@billdb ~]$ vi w.sh


###Hayat code - dbv output filter


cd /home/oracle

rm mydbv.log


echo "-----dbv started for file -------`date +"%Y-%m-%d %T"` " >> mydbv.log

echo "      "     >>  mydbv.log


dbv file=/u01/app/oracle/oradata/BILLDB/avdf_aud_data01.dbf >> mydbv.log 2>&1

dbv file=/u01/app/oracle/oradata/BILLDB/users01.dbf >> mydbv.log 2>&1

dbv file=/u01/app/oracle/oradata/BILLDB/sysaux01.dbf >> mydbv.log 2>&1

dbv file=/u01/app/oracle/oradata/BILLDB/undotbs01.dbf >> mydbv.log 2>&1


echo "  "     >>  mydbv.log

echo "--------------------dbv ended for files ---------------`date +"%Y-%m-%d %T"`" >> mydbv.log


##### filter revlent data


rm /home/oracle/dbv_enc_apply_status.txt


echo " ----------- filter DB verify encryption checking started -----------`date +"%Y-%m-%d %T"`"     >>  dbv_enc_apply_status.txt

echo " "     >>  dbv_enc_apply_status.txt


grep -E -w 'DBVERIFY - Verification starting|Total Pages Encrypted' mydbv.log >>  dbv_enc_apply_status.txt


echo "    "     >>  dbv_enc_apply_status.txt

echo " ----------- filter DB verify encryption checking ended -----------`date +"%Y-%m-%d %T"`"     >>  dbv_enc_apply_status.txt



Extra command to merge multiple files: 

If parallel log files generated for large number of data files

cat mylog*.txt >> alldf_mylog.txt

Or

$ cat file1 file2 file3 file4 file5  > alldf_mylog.txt

Or

for i in mylog*.txt ;   do cat $i >> alldf_mylog.txt ;  done

Or

awk '1' mylog*.txt  > alldf_mylog.txt