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?
 

Comments:

Surely it's more that -f to cut is : field delimiter, and so you're saying that the line actually has at least 2 fields, NULL + /etc . . .

Just like the following CSV format should suggest that there's a null field in position 1
,1,2,3

At least that's how I've always thought about it :)

Posted by mike on April 07, 2008 at 03:40 PM IST #

Do it in one command. Use nawk:

strings /usr/apache/bin/httpd |nawk '/SERVER_CONFIG_FILE/ { split($0, a, "\"") ;
print a[2] }'

:-)

Posted by Chris Gerhard on April 07, 2008 at 05:14 PM IST #

Chris,

Old bad habits die hard! Every new incident reminds me that it is time I learned awk! :-)

Posted by Madhan Kumar on April 07, 2008 at 05:16 PM IST #

Post a Comment:
  • HTML Syntax: NOT allowed

This blog copyright 2009 by maddy