
Terminal - Commands tagged awk - 252 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.
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.
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.
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.
This is sample output - yours may be different.
That's the easiest way to do it. -I (or capital i) display all network addresses of a host
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.
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.
netstat -tn | grep :80 | awk '{print $5}'| grep -v ':80' | cut -f1 -d: |cut -f1,2,3 -d. | sort | uniq -c| sort -n
This is sample output - yours may be different.
1 192.168.1.5
5 192.168.1.2
8 192.168.1.52
15 192.168.1.3
19 192.168.1.30
cut -f1,2 - IP range 16
cut -f1,2,3 - IP range 24
cut -f1,2,3,4 - IP range 24
svn status | grep "^M" | while read entry; do file=`echo $entry | awk '{print $2}'`; echo $file; svn revert $file; done
This is sample output - yours may be different.
my/files.txt
Reverted 'my/files.txt'
This command allows you to revert every modified file one-by-one in a while loop, but also after "echo $file;" you can do any sort of processing you might want to add before the revert happens.
awk -F'\t' '{print $0 >>$5.tsv}'
This is sample output - yours may be different.
Will split the std input lines into files grouped by the 5th column content.
cal 04 2012 | awk '{ $7 && X=$7 } END { print X }'
This is sample output - yours may be different.
If your locale has Monday as the first day of the week, like mine in the UK, change the two $7 into $6
echo `disklabel mfid1s4 | sed -n '$p' | awk '{print $2}'` / 1024 / 1024 | bc -l
This is sample output - yours may be different.
newops# disklabel mfid1s2
# /dev/mfid1s2:
8 partitions:
# size offset fstype [fsize bsize bps/cpg]
c: 1874849760 0 unused 0 0 # "raw" part, don't edit
d: 1874849760 0 4.2BSD 2048 16384 28552
newops# echo `disklabel mfid1s2 | sed -n '$p' | awk '{print $2}'` / 1024 / 1024 | bc -l
1787.99606323242187500000
cal 04 2012 | awk 'NF <= 7 { print $7 }' | grep -v "^$" | tail -1
This is sample output - yours may be different.
This is a little trickier than finding the last Sunday, because you know the last Sunday is in the first position of the last line. The trick is to use the NF less than or equal to 7 so it picks up all the lines then grep out any empty lines.
lynx -dump http://www.cooks4arab.com | awk '/http/{print $2}' | egrep "^https{0,1}"
This is sample output - yours may be different.
lynx -dump http://www.domain.com | awk '/http/{print $2}' | egrep "^https{0,1}"
This is sample output - yours may be different.
for k in $(git branch | sed /\*/d); do echo "$(git log -1 --pretty=format:"%ct" $k) $k"; done | sort -r | awk '{print $2}'
This is sample output - yours may be different.
master
testing
this-shit-works
Simpler and without all of the coloring gimmicks. This just returns a list of branches with the most recent first. This should be useful for cleaning your remotes.
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.
small update for this command to work with linux kernels 3.x
ps h --ppid $(cat /var/run/apache2.pid) | awk '{print"-p " $1}' | xargs sudo strace
This is sample output - yours may be different.
Like the original version except it does not include the parent apache process or the grep process and adds "sudo" so it can be run by user.
curl -s mobile.twitter.com/search | sed -n '/trend_footer_list/,/\ul>/p' | awk -F\> '{print $3}' | awk -F\< '{print $1}' | sed '/^$/d'
This is sample output - yours may be different.
Prints top 5 twitter topics. Not very well written at all but none of the others worked.
find /path/to/dir -iname "*.ext" -print0 | xargs -0 mplayer -really-quiet -cache 64 -vo dummy -ao dummy -identify 2>/dev/null | awk '/ID_LENGTH/{gsub(/ID_LENGTH=/,"")}{SUM += $1}END{ printf "%02d:%02d:%02d\n",SUM/3600,SUM%3600/60,SUM%60}'
This is sample output - yours may be different.
Improvement on Coderjoe's Solution. Gets rid of grep and cut (and implements them in awk) and specifies some different mplayer options that speed things up a bit.
awk 'FNR==100 {print;exit}' file
This is sample output - yours may be different.
This will save parsing time for operations on very big files.
awk '{cmd="date --date=\""$1"\" +\"%Y/%m/%d %H:%M:%S\" "; cmd | getline convdate; print cmd";"convdate }' file.txt
This is sample output - yours may be different.
date --date="Mon Feb 27 12:06:58 2012" +"%Y/%m/%d %H:%M:%S";2012/02/27 12:06:58
date --date="Mon Feb 27 12:11:15 2012" +"%Y/%m/%d %H:%M:%S";2012/02/27 12:11:15
date --date="Mon Feb 27 12:12:47 2012" +"%Y/%m/%d %H:%M:%S";2012/02/27 12:12:47
Convert readable date/time with `date` command
print "$(lsvg -Lo |xargs lsvg -L|grep "TOTAL PPs"|awk -F"(" '{print$2}'|sed -e "s/)//g" -e "s/megabytes/+/g"|xargs|sed -e "s/^/(/g" -e "s/+$/)\/1000/g"|bc ) GB"
This is sample output - yours may be different.
Not figured by me, but a colleague of mine.
See the total amount of data on an AIX machine.
sed -r 's/(\[|])//g' | awk ' { $1=strftime("%D %T",$1); print }'
This is sample output - yours may be different.
Input :
[1325199600] CURRENT SERVICE STATE: HOST01;Loopback;OK;HARD;1;Loopback0:UP:1 UP: OK
[1325199600] CURRENT SERVICE STATE: HOST01;Uptime Routers SFR;OK;HARD;1;Information only: 114 days
Ouput :
12/30/11 00:00:00 CURRENT SERVICE STATE: HOST01;Loopback;OK;HARD;1;Loopback0:UP:1 UP: OK
12/30/11 00:00:00 CURRENT SERVICE STATE: HOST01;Uptime Routers SFR;OK;HARD;1;Information only: 114 days
It remove the square bracket and convert UNIX time to human readable time for all line of a stream (or file).
ps -fea | grep PATTERN | awk {'print $2'} | xargs kill -9
This is sample output - yours may be different.
kill 28310: No such process
Kill all process that concide whit PATTERN