Oh, Thank you a ton Kai! It really works. And thank you for the great info about this useful utility. Now my changeset can be found on https://bitbucket.org/majid_aldharrab/glob2/changeset/3cb9d993c4b5/ and it's ready to get merged :).
2010/1/13 Kai Antweiler <[email protected]> > > I am not really familiar with this gawk command > > "The awk utility interprets a special-purpose programming language > that makes it possible to handle many data-reformatting jobs with just > a few lines of code." > http://www.gnu.org/software/gawk/ > > OK, I'll explain our case. > > The general structure is like this: > gawk '{...}' inputfile1 inputfile2 ... > outputfile > > where ">" is the standard redirecting operator of linux shells. > > The interior of the braces "{}" is executed for each line of each input > file. > A semicolon separates commands. > Braces combine commands. > > if (FILENAME == "arFile.txt") {...} else {...} > > FILENAME is a special variable that contains the name of the input > file that is currently processed. > > So if the current line comes from file "arFile.txt", execute the first > command block. > Otherwise execute the second. > > a[NR]=$0 > > NR is a special variable that is set to the line number in the current > file. > $0 is a special variable that contains the current line (i.e. its text). > In our case "a" becomes a variable with multiple entries. Each time > this statement is executed, a gets an entry that is indexed with the > current line number and set to $0. > > print $0 > > Print the current line. > > if ($0 ~ /,de/) {} > > If the current line somewhere contains the string ",de" execute the > following command block. Otherwise do nothing. > > print a[++i] > > "i" becomes a variable. When this command is executed the first time > "i" is set to "0" as default. > "++i" means: increment the value of "i" by 1 and pass the result. > ("i++" would mean: pass the value of "i" and increment "i" afterwards.) > > a[...] means: get the value of "a" at the index given in the brackets "[]". > > print ... > > Print it. > > > So what gawk does in our case, is: > It reads in the file "arFile.txt" and stores every line in "a[line > number]". > Then it reads the file "tutorial_part1.sgsl" and prints each line. If it > comes across a line that contains the string ",de", it additionally > prints a line from the arabic translation. The first time, the first > line. The second time, the second line. And so on. > The output is redirected by ">" into the file "tutorial_part1.sgsl.new". > Done. > > -- > Kai Antweiler > > > _______________________________________________ > glob2-devel mailing list > [email protected] > http://lists.nongnu.org/mailman/listinfo/glob2-devel >
_______________________________________________ glob2-devel mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/glob2-devel
