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,