> From: Federico Bruni <f...@inventati.org> > To: Dev <lilypond-devel@gnu.org> > Date: Thu, 20 Apr 2017 08:20:26 +0200 > Subject: help with bash script to translate @ref{} items in translated > manuals > Hi all > > I recently realized that @ref{} links should be translated otherwise PDF > links are broken (while HTML files still work fine without @ref{} > translated). > > Yesterday I started to manually translate all the @ref{} instances in the > italian web, usage and learning manuals. > Now I've come to the notation manual, which has too many items. > > [notation (translation %)]$ grep -oh -e @ref{.*} *.itely | sort -u | wc -l > 257 > [notation (translation %)]$ grep -oh -e @ref{.*} *.itely | wc -l > 702 > > 257 different @ref and a total of 702 @ref > > Not all these 257 ref are translated (as translation of this manual is not > complete yet), but most are. > So I decided to try a bash script, but I have a problem with a regexp, > which works fine in the terminal but not in the bash script. > > Enter Documentation/it/notation and run this: > > #!/bin/bash > LIST="$(grep -oh -e @ref{.*} *.itely | sort -u)" > for i in $LIST; do > echo $i > # echo -n "Replace" $i "with the translated node: " > # read NODE > # if $NODE=""; then exit > # else > # sed "s|$i|$NODE|g" *.itely > # fi > done > > You'll get something like: > > @ref{Tuplets} > @ref{Turkish > classical > music} > @ref{Typesetting > Gregorian > chant} > > > The problem is the space character, which is not matched in the bash > script. > Why? > > Thanks in advance > Federico >
Not sure if you'e found a solution in bash yet. As someone else mentioned, this is pretty straightforward in Perl: #!/usr/bin/perl # Usage: findRefs.pl <files> # # Find all references, from the files specified on the command line, # where references are defined as the contents inside strings like "@ref{}". # # Print the sorted, unique contents. my $file ; my $contents ; my $match ; my @matches ; my %refs ; my $ref ; local $/ = undef; foreach $file ( @ARGV ) { open my $fh, '<', $file or die "Couldn't open file: $!" ; $contents = <$fh> ; close $fh ; (@matches) = ( $contents =~ /\@ref\{(.*)\}/g ) ; foreach $match (@matches) { unless ( defined $refs{$match} ) { $refs{$match} = 'defined' ; } } @matches = () ; } foreach my $ref (sort keys %refs) { print $ref . "\n" ; } If you save that to a file findRefs.pl and make it executable, you might invoke it as: findRefs.pl Documentation/it/notation HTH, David Elaine Alt 415 . 341 .4954 "*Confusion is highly underrated*" ela...@flaminghakama.com self-immolation.info skype: flaming_hakama Producer ~ Composer ~ Instrumentalist -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- _______________________________________________ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel