
Terminal - Commands using awk - 984 results
tcpdump -ntr NAME_OF_CAPTURED_FILE.pcap 'tcp[13] = 0x02 and dst port 80' | awk '{print $4}' | tr . ' ' | awk '{print $1"."$2"."$3"."$4}' | sort | uniq -c | awk ' {print $2 "\t" $1 }'
This is sample output - yours may be different.
curl -s "http://subfusion.net/cgi-bin/quote.pl?quote=futurama&number=1" |awk '/<body><br><br><b><hr><br>/ {flag=1;next} /<br><br><hr><br>/{flag=0} flag {print}'
This is sample output - yours may be different.
"All humans are vermin in the eyes of Morbo!"
--Morbo
awk '{print $1}' /proc/net/dev|grep :|sed "s/:.*//g"
This is sample output - yours may be different.
grep -e "[sh]d[a-l][0-9]\?" /proc/partitions | awk '{print $4}'
This is sample output - yours may be different.
sda
sda1
sda2
sda3
sdb
sdb1
sdb2
sdb3
grep -e "[sh]d[a-l]$" /proc/partitions | awk '{print $4}' # for disks only
grep -e "[sh]d[a-l][0-9]\+" /proc/partitions | awk '{print $4}' # for partitions only
screen -x $(screen -ls | awk 'NR == 2 { print $1 }')
This is sample output - yours may be different.
sudo apt-get remove $(dpkg -l|awk '/^ii linux-image-/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic*//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic*\nlinux-image-%s-generic*\n",$0,$0,$0)}')
This is sample output - yours may be different.
Remove old kernels (*-generic and *-generic-pae) via apt-get on debian/ubuntu based systems. Tested on ubuntu 10.04 - 12.04.
wget --no-use-server-timestamps $(curl $(curl http://wallbase.cc/random/23/eqeq/1920x1080/0/100/20 | grep 'wallpaper/' | awk -F'"' '{print $2}' | head -n1) | grep -A4 bigwall | grep img | awk -F'"' '{print $2}'); feh --bg-center $(ls -1t | head -n1)
This is sample output - yours may be different.
ps wwwwuax|awk '/command/ { printf("kill -9 %s\n",$2) }'|/bin/sh
This is sample output - yours may be different.
Okay, commands like this are a bit of a personal peeve. awk(1) operates on a /pattern/ {action} paradigm and yet I see people leave out the /pattern/ portion of an awk command all the time, opting to use grep or sed instead. You'll save yourself some typing and time if you include the /pattern/ with your {action}.
cat /dev/urandom|od -t x1|awk 'NR > line { pos=int(rand()*15)+2;printf("%s",$pos);line=NR+(rand()*1000);digits = digits+2 } digits == 64 { print("\n");exit }'
This is sample output - yours may be different.
afca515ee00c0c92637ee8d7a476f8a380b969cc43e205bb086e622f2b77ebdd
Use this the next time you need to come up with a reasonably random bitstring, like for a WPA/WPA2 PSK or something. Takes a continuous stream of bytes coming from /dev/urandom, runs it through od(1), picking a random field ($0 and $1 excluded) from a random line and then prints it.
find . -type f -exec file '{}' + | grep shell | awk -F':' '{print $1}' | xargs chmod u+x
This is sample output - yours may be different.
Allows to change 'shell' compatible files execution bit even if their name is not *.sh
lsof -p `pidof pidgin` | awk '{ print $9 }'|egrep `hostname` | grep -o ">[^:]\+:" | tr -d ":>" | while read line; do host $line; done;
This is sample output - yours may be different.
wg-in-f125.1e100.net has address 239.200.3.125
wg-in-f125.1e100.net has address 239.12.3.125
wg-in-f125.1e100.net has address 173.194.78.125
wg-in-f125.1e100.net has address 239.220.3.125
baymsg1020225.gateway.edge.messenger.live.com has address 64.4.61.175
jabber-02-01-snc7.tfbnw.net has address 69.171.227.26
baymsg1020206.gateway.edge.messenger.live.com has address 64.4.61.156
export PATH= $(echo $PATH | tr ':' '\n' | awk '!/matching string/' | paste -sd:)
This is sample output - yours may be different.
If there are spaces won't work.
egrep '.*(("STATUS)|("HEAD)).*' http_access.2012.07.18.log | awk '{sum+=$11; ++n} END {print "Tot="sum"("n")";print "Avg="sum/n}'
This is sample output - yours may be different.
Tot=134020202(15201)
Avg=8816.54
Depending on your Apache access log configuration you may have to change the sum+=$11 to previous or next awk token.
Beware, usually in access log last token is time of response in microseconds, penultimate token is size of response in bytes. You may use this command line to calculate sum and average of responses sizes.
You can also refine the egrep regexp to match specific HTTP requests.
echo "DESCRIBE dbname.table_name" | mysql -u dbusername | awk '{print $1}' | grep -v Field
This is sample output - yours may be different.
user@machine:~$ echo "describe information_schema.COLUMNS" | mysql -u root | awk '{print $1}' | grep -v Field
TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
COLUMN_NAME
ORDINAL_POSITION
COLUMN_DEFAULT
IS_NULLABLE
DATA_TYPE
CHARACTER_MAXIMUM_LENGTH
CHARACTER_OCTET_LENGTH
NUMERIC_PRECISION
NUMERIC_SCALE
CHARACTER_SET_NAME
COLLATION_NAME
COLUMN_TYPE
COLUMN_KEY
EXTRA
PRIVILEGES
You can execute this inside an editor to get all the fields inside your buffer and do the magic, really usefull when your tables contain a giant list of fields.
egrep 'ServerAlias|ServerName' /etc/apache2/sites-enabled/*.conf | awk '{printf "%s\t%s\n",$2,$3}' | sed 's/www.//' | sort | uniq
This is sample output - yours may be different.
Get a list of all the unique hostnames from the apache configuration files. Handy to see what sites are running on a server. When i saw the command i had some ideas to make it shorter. Here is my version.
ip -f inet a | awk '/inet / { print $2 }'
This is sample output - yours may be different.
127.0.0.1/8
10.28.66.71/24
gives u each configured IP in a seperate line.
ip a s eth0 | awk -F"[/ ]+" '/inet / {print $3}'
This is sample output - yours may be different.
ip a s eth0 | awk '/inet / {print $2} | sed -e 's/\/..//g'
This is sample output - yours may be different.
ip a s eth0 | grep "inet " | head -n 1 | awk '{print $2}' | cut -f1 -d'/'
This is sample output - yours may be different.
Get the first IPv4 address of an interface
ifconfig | awk -F"[: ]+" '/inet addr/ {print $4}'
This is sample output - yours may be different.
ifconfig | grep "inet" | tail -1 | awk '{print $2}'
This is sample output - yours may be different.
ifconfig | grep "inet" | grep "broadcast" | awk '{print $2}'
This is sample output - yours may be different.
ps -fu $USER | awk {'print $2'} | xargs kill [-9]
This is sample output - yours may be different.
sudo apt-get remove $(dpkg -l|awk '/^ii linux-image-/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic-pae//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic*\nlinux-image-%s-generic*\n",$0,$0,$0)}')
This is sample output - yours may be different.
echo http://www.TheWebSiteName.com privatekeyword | md5sum | awk '{print substr($0,0,10)}'
This is sample output - yours may be different.
$ echo http://www.TheWebSiteName.com privatekeyword | md5sum | awk '{print substr($0,0,10)}'
3ac2dd2389
Create a bash function for easy reference
webPassword()
{
echo $1 $2 | md5sum | awk '{print substr($0,0,10)}'
}
alias webpwd=webPassword
Use like this.
webpwd www.commandlinefu.com MyPetNameHere