help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Extracting sections from code files


From: fatiparty
Subject: Re: Extracting sections from code files
Date: Thu, 4 Nov 2021 02:58:06 +0100 (CET)

Nov 3, 2021, 18:57 by dennistwilliamson@gmail.com:

>
>
> On Wed, Nov 3, 2021, 1:46 PM fatiparty--- via <> help-bash@gnu.org> > wrote:
>
>>
>> Nov 3, 2021, 17:39 by>> celvidge001@gmail.com>> :
>>  
>>  > On 03/11/2021 03:51 pm, fatiparty--- via wrote:
>>  >
>>  >> ## Mode: org
>>  >> #  Assigns shell positional parameters or changes the values of shell
>>  >> #  options.  The -- option assigns the positional parameters to the
>>  >> #  arguments of {set}, even when some of them start with an option
>>  >> #  prefix `-'.
>>  >> ## # End of org
>>  >>
>>  >> ;; Mode: org
>>  >> ;  Assigns shell positional parameters or changes the values of shell
>>  >> ;  options.  The -- option assigns the positional parameters to the
>>  >> ;  arguments of {set}, even when some of them start with an option
>>  >> ;  prefix `-'.
>>  >> ;; # End of org
>>  >>
>>  >> @c Mode: org
>>  >> @c Assigns shell positional parameters or changes the values of shell
>>  >> @c options.  The -- option assigns the positional parameters to the
>>  >> @c arguments of {set}, even when some of them start with an option
>>  >> @c prefix `-'.
>>  >> @c # End of org
>>  >>
>>  >
>>  > grep -v 'org$' testfile | cut -c4-
>>  >
>>  > -- 
>>  > Chris Elvidge
>>  > England
>>  >
>>  
>>  Have updated the bash function to use a single pattern charcl.  But the 
>> comments are not being removed. 
>>  
>>  capture ()
>>  {
>>  local efile="$1"
>>  
>>  local begorg endorg charcl
>>  
>>  charcl='^[[:space:]]*([#;!]+|@c|\/\/)[[:space:]]*'
>>  begorg="${charcl}"'Mode: org$'
>>  endorg="${charcl}"'# End of org$'
>>  
>>  awk -v ccls="$charcl" -v bego="$begorg" -v endo="$endorg" \
>>     '$0 ~ bego { found=1; next }
>>      $0 ~ endo { found=0; }
>>      found { sub(/ccls/,""); print }' "$efile"
>>  }
>>  
>>  
>>
>
> begrec is not begorg, etc.
>

You are right, but the biggest problem is  how to use charcl to remove the 
comment characters after extracting the sections between begorg and endorg  (or 
begrec and endrec).  I allow any number of repeats for # ; ! but no repeats for 
@c and //.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]