
Terminal - Commands using gawk - 32 results
find /some/path -type f | gawk -F/ '{print $NF}' | gawk -F. '/\./{print $NF}' | sort | uniq -c | sort -rn
This is sample output - yours may be different.
100 txt
25 gz
10 vim
3 gitignore
If you have GNU findutils, you can get only the file name with
find /some/path -type f -printf '%f\n'
instead of
find /some/path -type f | gawk -F/ '{print $NF}'
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=521826202&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
This is sample output - yours may be different.
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=4&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
This is sample output - yours may be different.
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=100000475200812&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
This is sample output - yours may be different.
grep -H voluntary_ctxt /proc/*/status |gawk '{ split($1,proc,"/"); if ( $2 > 10000000 ) { printf $2 " - Process : "; system("ps h -o cmd -p "proc[3]) } }' | sort -nk1,1 | sed 's/^/Context Switches: /g'
This is sample output - yours may be different.
Context Switches: 1097211 - Process : [migration/12]
Context Switches: 1500058 - Process : [migration/10]
Context Switches: 1558813 - Process : [migration/13]
Context Switches: 2207748 - Process : [migration/11]
Context Switches: 2516720 - Process : /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/server.err --open-files-limit=12288 --pid-file=/var/lib/mysql/server.pid
This command will find the highest context switches on a server and give you the process listing.
a=$(xwininfo |gawk 'BEGIN {FS="[x+ \t]*"} /-geometry/ {print int(($3+1)/2)*2"x"int(($4+1)/2)*2"+"$5"+"$6}') ; echo ${a} ; ffmpeg -f x11grab -s ${a} -r 10 -i :0.0 -sameq -f mp4 -s wvga -y /tmp/out.mpg
This is sample output - yours may be different.
...
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding
frame= 18 fps= 11 q=0.0 Lsize= 55kB time=1.80 bitrate= 252.5kbits/s
video:55kB audio:0kB global headers:0kB muxing overhead 1.626234%
Now we can capture only a specific window (we have to chose by clicking on it)
ffmpeg complains about "Frame size must be a multiple of 2" so we calculate the upper even number with (g)awk trickery.
We remove the grep, we are already using (g)awk here ....why losing time with grep !!! ;)
program | gawk 'BEGIN { l=systime() ; p="-- start --" } { t=systime(); print t-l "s " p; l=t; p=$0 } END { t=systime(); print t-l "s " p}'
This is sample output - yours may be different.
0s -- start --
0s Reading package lists...
34s dh_strip -papp-common
1s dh_compress -papp-common
4s dh_fixperms -papp-common
0s dh_makeshlibs -papp-common
0s dh_strip -papp-web
Prefixes each output line with time between it and the previous one.
ps auxww | grep application | grep processtobekilled | gawk '{print $2}' | grep -v grep | xargs kill -9
This is sample output - yours may be different.
You can also use gawk:
ps auxww | gawk '/application/' | gawk '/processtobekilled/' | gawk '{print $2}' | grep -v grep | xargs kill -9
ls -l | gawk -v FIELDWIDTHS='1 3 3 3' '{print $2}'
This is sample output - yours may be different.
$ lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=100003119823986&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
This is sample output - yours may be different.
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=Bilal Butt&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
This is sample output - yours may be different.
find -type f -printf "%S\t%p\n" 2>/dev/null | gawk '{if ($1 < 1.0) print $1 $2}'
This is sample output - yours may be different.
Prints the path/filename and sparseness of any sparse files (files that use less actual space than their total size because the filesystem treats large blocks of 00 bytes efficiently).
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=4&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
This is sample output - yours may be different.
gawk 'BEGIN {RS="\n\n"; if (ARGV[1]=="-i")IGNORECASE=1;ARGC=1}{if (IGNORECASE)Text[tolower($0)]=$0;else Text[$0]=$0 };END {N=asort(Text);for(i=1;i<=N;i++)printf "%s\n\n",Text[i]}' -i<Test.txt
This is sample output - yours may be different.
# Backup all MySQL Databases to individual files
for I in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump $I | gzip > "$I.sql.gz"; done
# backup local MySQL database into a folder and removes older then 5 days backups
mysqldump -uUSERNAME -pPASSWORD database | gzip > /path/to/db/files/db-backup-`date +%Y-%m-%d`.sql.gz ;find /path/to/db/files/* -mtime +5 -exec rm {} \;
# geoip information
curl -s "http://www.geody.com/geoip.php?ip=$(curl -s icanhazip.com)" | sed '/^IP:/!d;s/<[^>][^>]*>//g'
# List files contained within a zip archive
unzip -l <filename>
Sorts blank line delimited paragraphs. '-i' -- case insensitivity option -- removes redundant paragraphs in a case insensitive way, and then sorts in a case insensitive way.
If you search CommandLineFu with multiple anded terms searches, redundancy can ensue. This sorts the retrieved text (among other kinds of data), and removes the redundancy.
gawk 'BEGIN {RS="\n\n"; if (ARGV[1]=="-i"){IGNORECASE=1; ARGC=1}};{Text[NR]=$0};END {asort(Text);for (i=1;i<=NR;i++) printf "%s\n\n",Text[i] }' -i<Zip.txt
This is sample output - yours may be different.
# back up your commandlinefu contributed commands
curl http://www.commandlinefu.com/commands/by/<your username>/rss|gzip ->commandlinefu-contribs-backup-$(date +%Y-%m-%d-%H.%M.%S).rss.gz
# Backup all MySQL Databases to individual files
for db in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump $db | gzip > "/backups/mysqldump-$(hostname)-$db-$(date +%Y-%m-%d-%H.%M.%S).gz"; done
# Backup all MySQL Databases to individual files
for I in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump $I | gzip > "$I.sql.gz"; done
# Backup files older than 1 day on /home/dir, gzip them, moving old file to a dated file.
find /home/dir -mtime +1 -print -exec gzip -9 {} \; -exec mv {}.gz {}_`date +%F`.gz \;
Among other things, this allows the sorting of comment descriptions and command lines retrieved as text from CommandLineFu.com.
gawk '!/^[\t\ ]*#/{print $0}' filename | strings
This is sample output - yours may be different.
gawk '{n=$1;a=0;b=1;c=1;for(i=1;i<n;i++){c=a+b;a=b;b=c};print c}' << eof
This is sample output - yours may be different.
finish input with:
999
0
1
2
3
eof
26863810024485337815052569207027905710267776959038865271418527606059667101451514099303873236210167827650084004405807693119964697202348044908203804335127173454055409270617765081794282450393830849992803129229312
1
1
1
2
only take the first field on each row to compute the fibo on this number
slow2() { ionice -c3 renice -n 20 $(pstree `pidof $1` -p -a -u -A|gawk 'BEGIN{FS=","}{print $2}'|cut -f1 -d " ") ; }
This is sample output - yours may be different.
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?ninatodorovic&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
This is sample output - yours may be different.
pmap $(pgrep [ProcessName] -n) | gawk '/total/ { a=strtonum($2); b=int(a/1024); printf b};'
This is sample output - yours may be different.
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=4&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
This is sample output - yours may be different.
find . -maxdepth 1 ! -name '.' -execdir du -0 -s {} + | sort -znr | gawk 'BEGIN{ORS=RS="\0";} {sub($1 "\t", ""); print $0;}' | xargs -0 du -hs
This is sample output - yours may be different.
A little bit smaller, faster and should handle files with special characters in the name.
equery s | sed 's/(\|)/ /g' | sort -n -k 9 | gawk '{print $1" "$9/1048576"m"}'
This is sample output - yours may be different.
alanceil@kvirasim:03:06:2:0:~> equery s | sed 's/(\|)/ /g' | sort -n -k 9 | gawk '{print $1" "$9/1048576"m"}'
app-text/scrollkeeper-9999-r1: 0m
gnome-base/gail-1000: 0m
--- *snip* ---
dev-java/sun-jdk-1.6.0.13: 158.84m
games-puzzle/neverball-1.5.0: 174.607m
app-office/openoffice-bin-3.0.0: 380.035m
On a Gentoo system, this command will tell you which packets you have installed and sort them by how much space they consume. Good for finding out space-hogs when tidying up disk space.
DD=`cat /etc/my.cnf | sed "s/#.*//g;" | grep datadir | tr '=' ' ' | gawk '{print $2;}'` && ( cd $DD ; find . -mindepth 2 | grep -v db\.opt | sed 's/\.\///g; s/\....$//g; s/\//./;' | sort | uniq | tr '/' '.' | gawk '{print "CHECK TABLE","`"$1"`",";";}' )
This is sample output - yours may be different.
CHECK TABLE `mysql.columns_priv` ;
CHECK TABLE `mysql.db` ;
CHECK TABLE `mysql.func` ;
CHECK TABLE `mysql.help_category` ;
CHECK TABLE `mysql.help_keyword` ;
CHECK TABLE `mysql.help_relation` ;
CHECK TABLE `mysql.help_topic` ;
CHECK TABLE `mysql.host` ;
CHECK TABLE `mysql.tables_priv` ;
CHECK TABLE `mysql.time_zone` ;
CHECK TABLE `mysql.time_zone_leap_second` ;
CHECK TABLE `mysql.time_zone_name` ;
CHECK TABLE `mysql.time_zone_transition` ;
CHECK TABLE `mysql.time_zone_transition_type` ;
CHECK TABLE `mysql.user` ;
CHECK TABLE `mysql.user_info` ;
This command will generate "CHECK TABLE `db_name.table_name` ;" statements for all tables present in databases on a MySQL server, which can be piped into the mysql command. (Can also be altered to perform OPTIMIZE and REPAIR functions.)
Tested on MySQL 4.x and 5.x systems in a Linux environment under bash.
for x in `seq -w 1 30`; do sar -b -f /var/log/sa/sa$x | gawk '/Average/ {print $2}'; done
This is sample output - yours may be different.
4789.98
4286.45
4286.23
4028.34
4108.42
812.15
3171.27
3696.37
4584.12
You need sysstat and gawk for this to work.