
Terminal - Commands using awk - 984 results
ps -ef | awk '/process-name/ && !/awk/ {print}'
This is sample output - yours may be different.
$ ps -ef | awk '/mingetty/ && !/awk/ {print}'
root 4976 1 0 Jul01 tty1 00:00:00 /sbin/mingetty --noclear tty1
root 4977 1 0 Jul01 tty2 00:00:00 /sbin/mingetty tty2
root 4978 1 0 Jul01 tty3 00:00:00 /sbin/mingetty tty3
root 4979 1 0 Jul01 tty4 00:00:00 /sbin/mingetty tty4
root 4980 1 0 Jul01 tty5 00:00:00 /sbin/mingetty tty5
root 4981 1 0 Jul01 tty6 00:00:00 /sbin/mingetty tty6
This does the same thing as many of the 'grep' based alternatives but allows a more finite control over the output. For example if you only wanted the process ID you could change the command:
ps -ef | awk '/mingetty/ && !/awk/ {print $2}'
If you wanted to kill the returned PID's:
ps -ef | awk '/mingetty/ && !/awk/ {print $2}' | xargs -i kill {}
mysql -u<user> -p<password> -s -e 'DESCRIBE <table>' <database> | tail -n +1 | awk '{ printf($1",")}' | head -c -1
This is sample output - yours may be different.
awk < file.name '{ system("resolveip -s " $1) }'
This is sample output - yours may be different.
75.10.158.189
75.10.246.46
75.10.206.45
75.10.237.138
Given a file of FQDN, this simple command resolves the IP addresses of those Useful for log files or anything else that outputs domain names.
FFPID=$(pidof firefox-bin) && lsof -p $FFPID | awk '{ if($7>0) print ($7/1024/1024)" MB -- "$9; }' | grep ".mozilla" | sort -rn
This is sample output - yours may be different.
29.8359 MB -- /home/user/.mozilla/firefox/l0ad8wrj.default/urlclassifier3.sqlite
4.91797 MB -- /home/user/.mozilla/firefox/l0ad8wrj.default/places.sqlite
4.11752 MB -- /home/user/.mozilla/firefox/l0ad8wrj.default/Cache/_CACHE_003_
4.0147 MB -- /home/user/.mozilla/firefox/l0ad8wrj.default/XUL.mfasl
2.73011 MB -- /home/user/.mozilla/firefox/l0ad8wrj.default/extensions/{000a9d1c-beef-4f90-9363-039d445309b8}/lib/ff35/libgears.so
2.25571 MB -- /home/user/.mozilla/firefox/l0ad8wrj.default/extensions/{c45c406e-ab73-11d8-be73-000a95be3b12}/chrome/webdeveloper.jar
2.03915 MB -- /home/user/.mozilla/firefox/l0ad8wrj.default/Cache/_CACHE_001_
2.03215 MB -- /home/user/.mozilla/firefox/l0ad8wrj.default/Cache/_CACHE_002_
1.25815 MB -- /home/user/.mozilla/firefox/l0ad8wrj.default/extensions/{DDC359D1-844A-42a7-9AA1-88A850A938A8}/chrome/chrome.jar
0.382812 MB -- /home/user/.mozilla/firefox/l0ad8wrj.default/cookies.sqlite
0.191917 MB -- /home/user/.mozilla/firefox/l0ad8wrj.default/extensions/{a7c6cf7f-112c-4500-a7ea-39801a327e5f}/chrome/fireftp.jar
0.185547 MB -- /home/user/.mozilla/firefox/l0ad8wrj.default/signons.sqlite
0.166023 MB -- /home/user/.mozilla/firefox/l0ad8wrj.default/extensions/{582195F5-92E7-40a0-A127-DB71295901D7}/chrome/gmanager.jar
0.149414 MB -- /home/user/.mozilla/firefox/l0ad8wrj.default/ubiquity_ann.sqlite
Check which files are opened by Firefox then sort by largest size (in MB). You can see all files opened by just replacing grep to "/". Useful if you'd like to debug and check which extensions or files are taking too much memory resources in Firefox.
egrep "^lease" /var/lib/dhcp/db/dhcpd.leases |awk '{ print $2 }'
This is sample output - yours may be different.
192.168.0.73
192.168.0.99
192.168.0.38
192.168.0.77
192.168.0.98
192.168.0.46
192.168.0.13
You can use that to create a excludefile for nmap, to find hosts, with no DHCP lease in your DHCP range.
echo $PATH|awk -F: ' { for (i=1; i <= NF; i++) print $i }'
This is sample output - yours may be different.
awk -F ',' '{ x = x + $4 } END { print x }' test.csv
This is sample output - yours may be different.
find . -name \*.pdf -exec pdfinfo {} \; | grep Pages | sed -e "s/Pages:\s*//g" | awk '{ sum += $1;} END { print sum; }'
This is sample output - yours may be different.
ls -1 *.jpg | while read fn; do export pa=`exiv2 "$fn" | grep timestamp | awk '{ print $4 " " $5 ".jpg"}' | tr ":" "-"`; mv "$fn" "$pa"; done
This is sample output - yours may be different.
2008-09-26 20-59-03.jpg 2008-10-25 22-27-45.jpg 2008-12-19 22-07-51.jpg
2008-10-02 15-01-42.jpg 2008-10-25 22-28-02.jpg 2008-12-19 22-07-59.jpg
2008-10-02 15-25-34.jpg 2008-11-04 16-44-20.jpg 2008-12-19 22-09-54.jpg
Renames all the jpg files as their timestamps with ".jpg" extension.
This is sample output - yours may be different.
?Cat and grep? You can use only grep ("grep \. filename"). Better option is awk.
nslookup commandlinefu.com|sed 's/[^0-9. ]//g'|tail -n 1|awk -F " " '{print $2}'
This is sample output - yours may be different.
I use this in a script on my openwrt router to check if my DynDNS needs to be updated, saves your account from being banned for blank updates.
ifconfig | grep "0xffffffff" | awk '{ print $2 }' | xargs -n 1 ifconfig em0 delete
This is sample output - yours may be different.
curl -s http://isc.sans.org/sources.html|grep "ipinfo.html"|awk -F"ip=" {'print $2'}|awk -F"\"" {'print $1'}|xargs -n1 sudo iptables -A OUTPUT -j DROP -d > 2&>1
This is sample output - yours may be different.
This is sample output - yours may be different.
snd:~/trunk$ du -aB1m|awk '$1 >= 100'
130 ./webdev-tools
178 ./videos/peepcode-027-emacs.mov
102 ./videos/LispCast/Reddit Clone Episode 8 -- Continuations.flv
182 ./videos/LispCast/Reddit Clone Episode 3.flv
879 ./videos/LispCast
1010 ./videos
2138 .
netstat -ant | grep :80 | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -n
This is sample output - yours may be different.
1 200.79.138.35
1 201.145.29.126
2 189.135.132.228
The command could show you all conecctions if you skip "grep ESTABLISHED"
ifconfig | awk '/ddr:[0-9]/ {sub(/addr:/, ""); print $2}'
This is sample output - yours may be different.
ifconfig | awk '/ddr:[0-9]/ {sub(/addr:/, ""); print $2}'
192.168.1.23
127.0.0.1
The initial version of this command also outputted extra empty lines, so it went like this:
192.168.166.48
127.0.0.1
This happened on Ubuntu, i haven't tested on anything else.
ls foo*.jpg | awk '{print("mv "$1" "$1)}' | sed 's/foo/bar/2' | /bin/sh
This is sample output - yours may be different.
svn ls -R | egrep -v -e "\/$" | xargs svn blame | awk '{print $2}' | sort | uniq -c | sort -r
This is sample output - yours may be different.
2038 askedrelic
433 john
263 ryan
186 alice
167 bob
I'm working in a group project currently and annoyed at the lack of output by my teammates. Wanting hard metrics of how awesome I am and how awesome they aren't, I wrote this command up.
It will print a full repository listing of all files, remove the directories which confuse blame, run svn blame on each individual file, and tally the resulting line counts. It seems quite slow, depending on your repository location, because blame must hit the server for each individual file. You can remove the -R on the first part to print out the tallies for just the current directory.
ifconfig | awk -F':| +' '/ddr:/{print $4}'
This is sample output - yours may be different.
and, a lot uglier, with sed:
ifconfig | sed -n '/inet addr:/s/[^:]\+:\(\S\+\).*/\1/p'
Edit:
Wanted to be shorter than the perl version. Still think that the perl version is the best..
cat /var/log/secure.log | awk '{print substr($0,0,12)}' | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}'
This is sample output - yours may be different.
-macbook:~ root# cat /var/log/secure.log | awk '{print substr($0,0,12)}' | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}' | head
9 Jul 21 20:21 *********
9 Jul 20 19:46 *********
9 Jul 20 14:46 *********
7 Jul 23 16:55 *******
6 Jul 22 21:01 ******
6 Jul 20 21:05 ******
5 Jul 22 21:02 *****
4 Jul 20 21:25 ****
4 Jul 20 21:12 ****
Busiest seconds:
cat /var/log/secure.log | awk '{print substr($0,0,15)}' | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}'
awk '{print NR": "$0; for(i=1;i<=NF;++i)print "\t"i": "$i}'
This is sample output - yours may be different.
1: foo bar this is line one
1: foo
2: bar
3: this
4: is
5: line
6: one
2: blah blah some other stuff
1: blah
2: blah
3: some
4: other
5: stuff
Breaks down and numbers each line and it's fields. This is really useful when you are going to parse something with awk but aren't sure exactly where to start.
$ awk '{ split(sprintf("%1.3e", $1), b, "e"); p = substr("yzafpnum_kMGTPEZY", (b[2]/3)+9, 1); o = sprintf("%f", b[1] * (10 ^ (b[2]%3))); gsub(/\./, p, o); print substr( gensub(/_[[:digit:]]*/, "", "g", o), 1, 4); }' < test.dat
This is sample output - yours may be different.
1
10
100
1k23
10k0
100k
1M00
24k5
4k54
2P35
0m34
0n35
converts any number on the 'stdin' to SI notation. My version limits to 3 digits of precious (working with 10% resistors).
curl -u 'username' https://api.del.icio.us/v1/posts/all | sed 's/^.*href=//g;s/>.*$//g;s/"//g' | awk '{print $1}' | grep 'http'
This is sample output - yours may be different.
a variation of avi4now's command - thanks by the way!
/sbin/ifconfig | awk -F'[ :]+' '/inet addr/{print $4}'
This is sample output - yours may be different.
That one works on Linux. On BSD and Solaris, the ifconfig output is much easier to parse:
/sbin/ifconfig -a | awk '/inet/{print $2}'
cat `whereis mysqlbug | awk '{print $2}'` | grep 'CONFIGURE_LINE='
This is sample output - yours may be different.
CONFIGURE_LINE="./configure '--build=i486-linux-gnu' '--host=i486-linux-gnu' '--prefix=/usr' '--exec-prefix=/usr' '--libexecdir=/usr/sbin' '--datadir=/usr/share' '--localstatedir=/var/lib/mysql' '--includedir=/usr/include' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-server-suffix=-d7-ourdelta44' '--with-comment=(OurDelta - http://ourdelta.org/)' '--with-system-type=debian-linux-gnu' '--enable-shared' '--enable-static' '--enable-thread-safe-client' '--enable-assembler' '--enable-local-infile' '--with-big-tables' '--with-unix-socket-path=/var/run/mysqld/mysqld.sock' '--with-mysqld-user=mysql' '--with-libwrap' '--without-openssl' '--with-yassl' '--without-docs' '--without-readline' '--with-extra-charsets=all' '--with-innodb' '--with-archive-storage-engine' '--with-csv-storage-engine' '--with-federated-storage-engine' '--with-blackhole-storage-engine' '--with-sphinx-storage-engine' '--without-embedded-server' '--with-ndbcluster' '--with-ndb-ccflags=-fPIC' '--with-ndb-shm' '--without-ndb-sci' '--without-ndb-test' '--with-embedded-server' '--with-embedded-privilege-control' '--without-ndb-docs' 'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu' 'CC=gcc' 'CFLAGS=-DBIG_JOINS=1 -O2 -fPIC' 'CXX=g++' 'CXXFLAGS=-DBIG_JOINS=1 -felide-constructors -fno-rtti -O2'"