Reading the referers of this website, I found that someone reached it querying a search engine for
using AWK to find zero length files
AWK is a great tool but IMHO that is not its job.
I would have used a simple
find -size 0b
If you enjoyed this post, make sure you subscribe to my RSS feed!
Sorry, I’m addicted to puns. 
This is a note for me, you and Michele: do you want to get the sum of a set of integers? Try this one-liner:
awk '{TOT += $0} END {print TOT}' your_filename
Use $0 if your_filename has lines with one integer each, of course you can use $another_integer if you want to get the sum from a given column.
If you enjoyed this post, make sure you subscribe to my RSS feed!
Reading the referers of this website, I found that someone reached it querying a search engine for
subversion or svn export only changed files
This one-liner (that can be easily turned into a subversion hook) could do the task
for i in `svn log -r HEAD -v | grep "^ [MA]” | awk ‘{print $2}’`; do rsync -avR $i /basedir_of_your_export/; done
I’ve previously described here a slightly different problem.
If you enjoyed this post, make sure you subscribe to my RSS feed!
Reading the referers of this website, I found that someone reached it querying a search engine for
bash scripting validate file extension
I suppose they were looking for a script that, for example, when it finds a perl file, it is able to recognise it as such even if its extension is not pl.
Well, the following is my recipe for your Ferragosto Bash-becue
- Using your favourite language, populate an associative array with the strings that
file shows for the extensions that you are interested to map. Like:
php => PHP script text
pl => perl script text executable
- Within a Bash loop over the folder of your files:
- run
file against each file and save the string that it shows;
- using
awk, extract the extension of each file and look at the associative array: if the associated string is not the same that you have just found then the extension of your file is not validated.
- Don’t grill that much, please.
If you enjoyed this post, make sure you subscribe to my RSS feed!
Reading the referers of this website, I found that someone reached it querying a search engine for
awk remove file extension
Well, it’s definitely easy to achieve it if your files have just a “.” in their names. You can use this one-liner that works inverting the problem 
# substitute jpg with the extension you need (twice in the line)
for i in $(ls *jpg | awk -F "." '{print $1}'); do mv $i.jpg $i; done
If you enjoyed this post, make sure you subscribe to my RSS feed!
This one-liner helps in finding the file extensions of a given Subversion working copy:
find path_to_repos -type f | grep -v "/.svn/" | awk -F "/" '{print $NF}' | awk -F "." '{if (NF > 1) {print $NF}}' | sort | uniq
Its usage outside of Subversion is even more trivial.
If you enjoyed this post, make sure you subscribe to my RSS feed!