
Terminal - Commands using awk - 839 results
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.
ip li | grep ether | awk '{print $2}'
This is sample output - yours may be different.
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
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.
for i in *.txt; do j=`mktemp | awk -F. '{print $2".txt"}'`; mv "$i" "$j"; done
This is sample output - yours may be different.
hosts1.txt PjbKxiUXXM.txt
hosts2.txt q7qf8z15fx.txt
hosts3.txt qsIazSCGHm.txt
hosts4.txt GCWoo6oqMJ.txt
hosts5.txt 9CHc4MfCYM.txt
A simple way to rename a set of files to a unique, randomized file name.
cal | egrep -e '^ [0-9]|^[0-9]' | tr '\n' ' ' | awk '{print $NF}'
This is sample output - yours may be different.
$ cal | egrep -e '^ [0-9]|^[0-9]' | tr '\n' ' ' | awk '{print $NF}'
30
Returns last day of current month. Useful to implement a bash script backup based on a GFS strategy.
git remote -v | grep fetch | sed 's/\(.*github.com\)[:|/]\(.*\).git (fetch)/\2/' | awk {'print "https://github.com/" $1'} | xargs open
This is sample output - yours may be different.
Written for Mac OSX. When you are working in a project and want to open it on Github.com, just type "gh" and your default browser will open with the repo you are in. Works for submodules, and repo's that you don't own.
You'll need to copy / paste this command into a gh.sh file, then create an alias in your bash or zsh profile to the gh.sh script. Detailed instructions here if you still need help:
http://gist.github.com/1917716
svn stat | grep ^\! | awk '{print $2}' | xargs svn del
This is sample output - yours may be different.
Sometimes cache-files or garbage gets added to your SVN repository. This is the way I normally clean up those when the actual files are already gone.
diff -Naur /source/path /target/path --brief | awk '{print "cp " $2 " " $4}' | sh
This is sample output - yours may be different.
I use this a lot to sync changes between folders that don't share a SVN or GIT repository. If you want to preview the command before executing, just leave out the last part ("| sh")
for a in $(find . -xdev -type f -printf '%i\n'|sort|uniq -d);do find . -xdev -inum $a -printf '%s %i %m %n %U %G %AD %Ar %p\n';done|sort -n|awk '{if(x!=$2){print "---"};x=$2;print $0}'
This is sample output - yours may be different.
157 10840 644 2 1000 1000 04/09/12 02:23:44 PM ./bookmarks.xml
157 10840 644 2 1000 1000 04/09/12 02:23:44 PM ./mydir/bookmarks.xml
---
1987 10845 644 3 1000 1000 04/09/12 02:23:44 PM ./kst.gif
1987 10845 644 3 1000 1000 04/09/12 02:23:44 PM ./mydir/neki.gif~
1987 10845 644 3 1000 1000 04/09/12 02:23:44 PM ./mydir/text.gif
---
1988 10846 644 2 1000 1000 04/09/12 02:23:44 PM ./mydir/neki1.gif
1988 10846 644 2 1000 1000 04/09/12 02:23:44 PM ./mydir/neki.gif
The listing will be nice separated with dashes in chunks of identical files.
Output format:
Size Inode Mode Count_of_identical_files UID GID Date Time Path/Filename
yes "" | cat -n | awk '{print "S=`echo All work and no play makes Jack a dull boy. | cut -c",($1 - 1) % 43 + 1 "`;echo -n \"$S\";seq 500000 > /dev/null"}'| bash
This is sample output - yours may be different.
All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All awork and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.All work and no play makes Jack a dull boy.
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.
history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -nr | head
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.
small update for this command to work with linux kernels 3.x
apt-get -s upgrade | awk '/[0-9]+ upgraded,/ {print $1 " package updates are available"}'
This is sample output - yours may be different.
65 package updates are available
This let's you find out the total packages that have available upgrades. Usefull if you want to check or show the total available upgrades on your system.
ps aux | awk '$11!~/\[*\]/ {print $6/1024" Mb --> "$11,$12,$13,$14}' | sort -g
This is sample output - yours may be different.
Works on most unixes, on OpenBSD replace the "-g" parameter at the sort with a "-n".
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.
du -s $(ls -l | grep '^d' | awk '{print $9}') | sort -nr
This is sample output - yours may be different.
adb shell ps | grep my.app.packagename | awk '{print $2}' | xargs -I ? sh -c "adb logcat -v time | grep ?"
This is sample output - yours may be different.
free -m | awk '/cache:/ {print $4}'
This is sample output - yours may be different.
Does not output the word "shared" so you can easily store this number in a variable.
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.
aspectRatio () { for i in `seq 1 1000 `; do awk "BEGIN {print $1/$i, $2/$i}"; done |grep -v "\."; }
This is sample output - yours may be different.
1920 1200
960 600
640 400
480 300
384 240
320 200
240 150
192 120
160 100
128 80
120 75
96 60
80 50
64 40
48 30
40 25
32 20
24 15
16 10
8 5
EG: aspectRatio 1920 1200
For display a image in full screen it should be in any of the resolution obtained from the output. So resize an image to any of it and you can display it in full screen
For general aspect ratio :
aspectRatio () { for i in `seq 1 1000 `; do awk "BEGIN {print $1/$i, $2/$i}"; done |grep -v "\." |tail -1; }
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.
head -n1 nation.tbl | sed 's/\(.\)/\1\n/g' | sort | uniq -c | grep \| | awk '{ print $1 }'
This is sample output - yours may be different.