Bash tricks
What is my bash
echo "$SHELL" && ps -p $$
Manipulating a text file
Below is a sample text file and following are common tasks performed on the file.
example.txt
admin.examplelike.com.red.
files.examplelike.com.red.
examplelike.com.red.
imports.examplelike.com.red.
vpn.examplelike.com.red.
Remove char "dot" at the end of line from file
cat example.txt| sed 's/\.$//g'
Replace newline with comma
cat example.txt| tr '\n' ', '
extract domains from zonetransfer for hosts file
zonetransfer.txt
; <<>> DiG 9.18.11-2-Debian <<>> axfr @10.11.11.29 examplelike.com
; (1 server found)
;; global options: +cmd
examplelike.com. 604800 IN SOA localhost. root.localhost. 2 604800 86400 2419200 604800
examplelike.com. 604800 IN AAAA ::1
examplelike.com. 604800 IN NS localhost.
examplelike.com. 604800 IN A 127.0.0.1
administrator1.examplelike.com. 604800 IN A 127.0.0.1
hr.examplelike.com. 604800 IN A 127.0.0.1
uploads.examplelike.com. 604800 IN A 127.0.0.1
examplelike.com. 604800 IN SOA localhost. root.localhost. 2 604800 86400 2419200 604800
;; Query time: 139 msec
;; SERVER: 10.11.11.29#53(10.11.11.29) (TCP)
;; WHEN: Mon Apr 17 08:09:05 EDT 2021
;; XFR size: 8 records (messages 1, bytes 289)
cat zonetransfer.txt | awk '/604800/ {print $1}' | sort -u | tr '\n' ' ' | sed 's/\. / /g'