Monday Apr 07, 2008

I encountered a rather unusual situation that made me realize that my understanding of "cut" command is not as good as I thought it to be! 

 Take this example:

bash-3.00#  strings /usr/apache/bin/httpd |grep SERVER_CONFIG_FILE|cut -f2 -d"="
"/etc/apache/httpd.conf"

Now from the above output, I assume that there is just one field and that too it is within the delimiter "

Not so as per the following output:

bash-3.00#  strings /usr/apache/bin/httpd |grep SERVER_CONFIG_FILE|cut -f2 -d"="|cut -f1 -d"\""

bash-3.00#

So by simple trial and error method, I right shift field by one and give field# as 2:

bash-3.00#  strings /usr/apache/bin/httpd |grep SERVER_CONFIG_FILE|cut -f2 -d"="|cut -f2 -d"\""
/etc/apache/httpd.conf

Any expert opinion on this behaviour?
 

This blog copyright 2009 by maddy