pull the first comment from files

February 25, 2009 at 07:50:49
Specs: Unix

I want to write a script which will go through a SQL directory and pull the "flower box" from each file, which just means I need to get all the text between the first /* and the first */. Any help is appreciated.


See More: pull the first comment from files

Report •

February 28, 2009 at 11:35:39
This is a nasty yet interesting problem. I'm using Solaris with korn shell. My strategy was to use awk to delete the /* and delete the */ and stop processing the file. I had trouble using */ in awk. I decided to delete // in sed and replace */ with //.

I pipe that output to awk. I replace the first // and stop processing. It's a kludge, but it seems to work. (replace nawk with awk if you aren't using Solaris)


sed  -e 's!\/\*!!g' -e 's!\*\/!\/\/!g' filename|nawk ' {
if(gsub("\/\/","") > 0)
   print $0
   print $0
} '

Concerning your SQLdirectory requirement: change to the directory in question.  Surround the script I demo'ed above in a for loop:

for i in * 

change the variable to $i

Report •
Related Solutions

Ask Question