Записать этот Псевдокод с Regex

1 ответ

Если я правильно понимаю, вы ищете что-то вроде этого (в Bash ):

#!/usr/bin/env bash

## avoid errors if a directory has no *tex files
shopt -s nullglob

directories=("Cardiology" "Rheumatology" "Surgery");

## Change this to set whichever options you want.
printf "%s\n%s\n" "\documentclass{YOURCLASS}" "\begin{document}"

for directory in ${directories[@]}
do
    ## Reset the counter, avoid empty sections.
    c=0;
    for file in "$directory"/*tex
    do
        let c++
        [ "$c" -eq 1 ] && printf "\n%s\n" "\section{$directory}"
        ## Extract the wanted lines
        perl -lne '$a=1 && print "" if /\\begin{question}/; 
                  print if $a==1;
                  $a=0 if /\\end{question}/;' "$file" 
        echo ""
    done
done
echo "\end{document}"

Если вы запускаете этот скрипт из каталога, который содержит кардиологию и т. Д., Он должен обеспечивать так:

2
27.01.2020, 22:13

Теги

Похожие вопросы