
Terminal - Commands tagged awk - 117 results
man $(/bin/ls /bin | awk '{ cmd[i++] = $0 } END { srand(); print cmd[int(rand()*length(cmd))]; }')
This is sample output - yours may be different.
Build an awk array with all commands and then select a random one at the end.
This avoids spawning extra processes for counting with wc or generating random numbers.
Explicitly call /bin/ls to avoid interactions with aliases.
dir="/bin"; man $(ls $dir |sed -n "$(echo $(( $RANDOM % $(ls $dir |wc -l | awk "{ print $1; }" ) + 1 )) )p")
This is sample output - yours may be different.
Broaden your knowledge of the utilities available to you in no particular order whatsoever! Then use that knowledge to create more nifty one-liners that you can post here. =p
Takes a random number modulo the number of files in $dir, prints the filename corresponding to that number, and passes it as an argument to man.
svn status | grep "^\?" | awk '{print $2}' | xargs svn add
This is sample output - yours may be different.
When working on a big proeject with SVN, you create quite much files, for now! Can just sit here and type svn add for all of them!
svn status will return a list of all of file which get ?(not add), "M"(Modified), "D"(Deleted)! This code just grep "?" flag, then add it into SVN again!
seq 8 | awk '{print "e(" $0 ")" }' | bc -l
This is sample output - yours may be different.
2.71828182845904523536
7.38905609893065022723
20.08553692318766774092
54.59815003314423907811
148.41315910257660342111
403.42879349273512260838
1096.63315842845859926372
2980.95798704172827474359
If you want a sequence that can be plotted, do:
seq 8 | awk '{print "e(" $0 ")" }' | bc -l | awk '{print NR " " $0}'
Other bc functions include s (sine), c (cosine), l (log) and j (bessel). See the man page for details.
curl -sL 'www.commandlinefu.com/commands/random' | awk -F'</?[^>]+>' '/"command"/{print $2}'
This is sample output - yours may be different.
Splitting on tags in awk is a handy way to parse html.
svn st | grep -e '^M' | awk '{print $2}' | xargs svn revert
This is sample output - yours may be different.
ip route | awk '/default/{print $3}'
This is sample output - yours may be different.
netstat -rn | awk '/UG/{print $2}'
This is sample output - yours may be different.
Tested on CentOS, Ubuntu, and MacOS.
lsof /dev/snd/pcm*p /dev/dsp | awk ' { print $2 }' | xargs kill
This is sample output - yours may be different.
for when a program is hogging the sound output. finds, and kills. add -9 to the end for wedged processes. add in 'grep ^program' after lsof to filter.
awk '$1~/^DocumentRoot/{print $2}' /etc/apache2/sites-available/default
This is sample output - yours may be different.
awk 'NR==linenumber' filename
This is sample output - yours may be different.
curl -s "http://www.socrata.com/api/views/vedg-c5sb/rows.json?search=Axelrod" | grep "data\" :" | awk '{ print $17 }'
This is sample output - yours may be different.
Query the Socrata Open Data API being used by the White House to find any employee's salary using curl, grep and awk.
Change the value of the search parameter (example uses Axelrod) to the name of any White House staffer to see their annual salary.
ifconfig eth0 | awk '/inet / {print $2}' | cut -d ':' -f2
This is sample output - yours may be different.
wget -O - http://www.commandlinefu.com/commands/browse/rss 2>/dev/null | awk '/\s*<title/ {z=match($0, /CDATA\[([^\]]*)\]/, b);print b[1]} /\s*<description/ {c=match($0, /code>(.*)<\/code>/, d);print d[1]} ' | grep -v "^$"
This is sample output - yours may be different.
A Quick variation to the latest commands list with the new-lines skipped. This is faster to read.
ifconfig eth0 | grep "inet " | cut -d ':' -f2 | awk '{print $1}'
This is sample output - yours may be different.
I've been using it in a script to build from scratch proxy servers.
ac -d | awk '{h=int($NF); m=($NF-h)*60; s=int((m-int(m))*60); m=int(m); print $0" = "h"h "m"m "s"s "}'
This is sample output - yours may be different.
Jun 2 total 46.46 = 46h 27m 36s
Jun 3 total 59.86 = 59h 51m 35s
Jun 4 total 81.64 = 81h 38m 24s
Jun 5 total 73.41 = 73h 24m 35s
Jun 6 total 19.80 = 19h 48m 0s
Jun 7 total 43.26 = 43h 15m 35s
Jun 8 total 54.47 = 54h 28m 11s
Jun 9 total 76.59 = 76h 35m 24s
Jun 10 total 92.50 = 92h 30m 0s
Jun 11 total 46.75 = 46h 45m 0s
Jun 12 total 30.66 = 30h 39m 36s
Jun 13 total 40.65 = 40h 38m 59s
Jun 14 total 60.08 = 60h 4m 47s
Jun 15 total 75.36 = 75h 21m 35s
Jun 16 total 87.57 = 87h 34m 11s
Jun 17 total 83.92 = 83h 55m 12s
Jun 18 total 93.14 = 93h 8m 24s
Jun 19 total 105.85 = 105h 50m 59s
Jun 20 total 51.03 = 51h 1m 48s
Jun 21 total 36.27 = 36h 16m 12s
Jun 22 total 76.69 = 76h 41m 23s
Jun 23 total 52.55 = 52h 32m 59s
Today total 29.55 = 29h 33m 0s
'ac' is included in the package 'acct', which is described as "The GNU Accounting utilities for process and login accounting". Other interesting flags are:
* print statistics for a specified user
ac -d username
* print statistics for all the users
ac -p
With my command, the output is also printed in a sexagesimal, more readable, style.
vimlint(){ eval $(xmllint --noout "$1" 2>&1 | awk -F: '/parser error/{print "vim \""$1"\" +"$2; exit}'); }
This is sample output - yours may be different.
Validate a file using xmllint. If there are parser errors, edit the file in vim at the line of the first error.
svn st | awk '{if ($1 ~ "?") print $2}' | xargs svn add
This is sample output - yours may be different.
No need for grep, let awk do the match. This will not behave properly if the filenames contains whitespace, which is awk's default field separator.
aptitude remove $(dpkg -l|egrep '^ii linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`)
This is sample output - yours may be different.
The following packages will be REMOVED:
linux-image-2.6.32-3-amd64 linux-image-amd64
0 packages upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 99.6MB will be freed.
Would download/install/remove packages.
# `uname -r` = "2.6.34-dbb-deb"
This should do the same thing and is about 70 chars shorter.
sudo lvdisplay |awk '/LV Name/{blockdev=$3} /Block device/{bdid=$3; sub("[0-9]*:","dm-",bdid); print bdid,blockdev;}'
This is sample output - yours may be different.
dm-0 /dev/storage/root
dm-1 /dev/storage/swap_1
Emits the device names which will be printed by iostat for an LVM volume; doesn't show the names for the underlying devices when snapshots are being used (the -cow and -real devices in /dev/mapper)
fbemailscraper YourFBEmail Password
This is sample output - yours may be different.
awk '(length>t) {t=length} END {print t}' *.cpp
This is sample output - yours may be different.
tail -n2000 /var/www/domains/*/*/logs/access_log | awk '{print $1}' | sort | uniq -c | sort -n | awk '{ if ($1 > 20)print $1,$2}'
This is sample output - yours may be different.
netstat -an | awk '/tcp/ {print $6}' | sort | uniq -c
This is sample output - yours may be different.
9 ESTABLISHED
9 LISTEN
1 SYN_SENT
Counts TCP states from Netstat and displays in an ordered list.
echo "Keyword?";read keyword;query="http://www.shoutcast.com/sbin/newxml.phtml?search="$keyword"";curl -s $query |awk -F '"' 'NR <= 4 {next}NR>15{exit}{sub(/SHOUTcast.com/,"http://yp.shoutcast.com/sbin/tunein-station.pls?id="$6)}{print i++" )"$2}'
This is sample output - yours may be different.
0 )friskyRadio feelin frisky? [Dance, Trance, House and Techno] - [http://yp.shoutcast.com/sbin/tunein-station.pls?id=1745]
1 )Chillout Dreams - D I G I T A L L Y - I M P O R T E D - relax to the sounds of dream and ibiza style - [http://yp.shoutcast.com/sbin/tunein-station.pls?id=7307]
2 )1.FM - The Chillout Lounge - [http://yp.shoutcast.com/sbin/tunein-station.pls?id=5513]
3 )#MUSIK.LOUNGE - WWW.RAUTEMUSIK.FM - 24H CHILLOUT AMBIENT SMOOTH JAZZ DOWNTEMPO LATIN SOUL AND MORE! - [http://yp.shoutcast.com/sbin/tunein-station.pls?id=2477]
4 )PsyChill - D I G I T A L L Y - I M P O R T E D - downtempo psychedelic dub grooves, goa ambient, and - [http://yp.shoutcast.com/sbin/tunein-station.pls?id=9621]
5 )4CLUBBERS - [http://yp.shoutcast.com/sbin/tunein-station.pls?id=94142]
6 )Chilltrax - The World's Chillout Channel - [http://yp.shoutcast.com/sbin/tunein-station.pls?id=8734]
7 )Ambient - D I G I T A L L Y - I M P O R T E D - a blend of ambient, downtempo, and chillout - [http://yp.shoutcast.com/sbin/tunein-station.pls?id=46573]
8 )ZenRadio.FM: Zen Radio (tm) - Relaxation Meditation Concentration Peace Yoga Relaxare Chillout Loung - [http://yp.shoutcast.com/sbin/tunein-station.pls?id=2979]
9 )Mountain Chill - The Planet's Destination for Chill - [http://yp.shoutcast.com/sbin/tunein-station.pls?id=4324]
10 )_-_ P S Y C H E D E L I K . C O M -_- 192KBITS Ambient Psychedelic Chillout - Psychedelik.com - - [http://yp.shoutcast.com/sbin/tunein-station.pls?id=2835]
Searches for web radio by submitted keyword and returns the station name and the link for listing .
May be enhanced to read user's selection and submit it to mplayer.