Skip to main content
edited title
Link
Anthon
  • 81.4k
  • 42
  • 174
  • 228

Awk. Ignore lines that start with two possible patterns

II'm trying to analyse a source code and output each different function or subroutine to a file. My problem is that the source code can be something like this:

SUBROUTINE ABC --- END SUBROUTINE --- #SUBROUTINE to compute... SUBROUTINE Dummy --- WRITE SUBROUTINE XX has finished... END SUBROUTINE 

So, I am able to avoid the commented lines with the following command.

 awk 'BEGIN{IGNORECASE=1};/^[^#]*subroutine/{flag=1;s="tmp_s_"++i}/end subroutine/{flag=0} flag {print $0 > s}' $sourcecodefile 

But I want to avoid also the lines that have WRITE before the word Subroutine. I try this command but it doesn't work properly:

 awk 'BEGIN{IGNORECASE=1};/[^#|WRITE]*subroutine/{flag=1;s="tmp_s_"++i}/end subroutine/{flag=0} flag {print $0 > s}' $sourcecodefile 

If somebody knows how to solve this problem I will appreciate your response. Thank you in advance for your help.

I trying to analyse a source code and output each different function or subroutine to a file. My problem is that the source code can be something like this:

SUBROUTINE ABC --- END SUBROUTINE --- #SUBROUTINE to compute... SUBROUTINE Dummy --- WRITE SUBROUTINE XX has finished... END SUBROUTINE 

So, I am able to avoid the commented lines with the following command.

 awk 'BEGIN{IGNORECASE=1};/^[^#]*subroutine/{flag=1;s="tmp_s_"++i}/end subroutine/{flag=0} flag {print $0 > s}' $sourcecodefile 

But I want to avoid also the lines that have WRITE before the word Subroutine. I try this command but it doesn't work properly:

 awk 'BEGIN{IGNORECASE=1};/[^#|WRITE]*subroutine/{flag=1;s="tmp_s_"++i}/end subroutine/{flag=0} flag {print $0 > s}' $sourcecodefile 

If somebody knows how to solve this problem I will appreciate your response. Thank you in advance for your help.

I'm trying to analyse a source code and output each different function or subroutine to a file. My problem is that the source code can be something like this:

SUBROUTINE ABC --- END SUBROUTINE --- #SUBROUTINE to compute... SUBROUTINE Dummy --- WRITE SUBROUTINE XX has finished... END SUBROUTINE 

So, I am able to avoid the commented lines with the following command.

awk 'BEGIN{IGNORECASE=1};/^[^#]*subroutine/{flag=1;s="tmp_s_"++i}/end subroutine/{flag=0} flag {print $0 > s}' $sourcecodefile 

But I want to avoid also the lines that have WRITE before the word Subroutine. I try this command but it doesn't work properly:

awk 'BEGIN{IGNORECASE=1};/[^#|WRITE]*subroutine/{flag=1;s="tmp_s_"++i}/end subroutine/{flag=0} flag {print $0 > s}' $sourcecodefile 
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266
Source Link
Loading