
Terminal - Commands using gawk - 25 results
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.
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.
hddtemp /dev/sda /dev/sdb /dev/hda /dev/hdb | gawk '{print $NF}' | perl -n -e '$_ =~ s/(\d+)/print "$1 "/eg }{ print "\n"'
This is sample output - yours may be different.
get a list of temps of your hard-drives.
psql -U postgres -lAt | gawk -F\| '$1 !~ /^template/ && $1 !~ /^postgres/ && NF > 1 {print $1}'
This is sample output - yours may be different.
screen -ls | grep pts | gawk '{ split($1, x, "."); print x[1] }' | while read i; do gnome-terminal -e screen\ -dx\ $i; done
This is sample output - yours may be different.
connects to all the screen instances running.
find . -type f -print0 | xargs -r0 stat -c %Y\ %n | sort -rn | gawk '{sub(/.\//,"",$2); print $2}' > /tmp/playlist.m3u
This is sample output - yours may be different.
Tekzilla_Daily_Tip_HD_Quicktime/Firefox_Save_Websites_As_An_Image_-_Tekzilla_Daily_Tip.mp4
MacBreak_Weekly/MacBreak_Weekly_130_I_Did_A_Fiduciary_Dooty.mp3
Buzz_Out_Loud_from_CNET/Buzz_Out_Loud_922_Hot_and_junky.mp3
The_Totally_Rad_Show_HD_Quicktime/Nash_Out_-_Halo_Wars,_Street_Fighter_The_Legend_of_Chun_Li,_Green_Hornet_and_Clue_news,_Oscar_wager_results_-_The_Totally_Rad_Show.mp4
FRAK/FRAK_0.0.5.mp4
Tekzilla_Daily_Tip_HD_Quicktime/OS_X_Perfect_Windows_Management_Expose_and_Spaces_Together_-_Tekzilla_Daily_Tip.mp4
IT_Conversations/Dion_Almaer,_Ben_Galbraith_-_Bespin.mp3
Leo_Laporte_-_The_Tech_Guy/Leo_Laporte_-_The_Tech_Guy_539.mp3
Systm_HD_Quicktime/UPS_+_Car_Battery_=_More_Computing_Or_a_48_Hour_Disco_Ball_-_Systm.mp4
Praia_das_Mas/Praia_das_Mas_3.m4a
.....
I use this to generate a playlist with all the podcasts I listen to.
Ordered from most recent to older.
mysql -u uname dbname -e "show tables" | grep -v Tables_in | grep -v "+" | gawk '{print "optimize table " $1 ";"}' | mysql -u uname dbname
This is sample output - yours may be different.
mysql -u uname dbname -e "show tables" | grep -v Tables_in | grep -v "+" | gawk '{print "drop table " $1 ";"}' | mysql -u uname dbname
This is sample output - yours may be different.
sudo lsof | awk '{printf("%s %s %s\n", $1, $3, $NF)}' | grep -v "(" | sort -k 4 | gawk '$NF==prv{ct++;next} {printf("%d %s\n",ct,$0);ct=1;prv=$NF}' | uniq | sort -nr
This is sample output - yours may be different.