[Top][All Lists]

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

Re: [glob2-devel] Re: Tutorial translation isn't detected

From: Kai Antweiler
Subject: Re: [glob2-devel] Re: Tutorial translation isn't detected
Date: Tue, 12 Jan 2010 22:23:53 +0100

> 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."

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.


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 "".

Kai Antweiler

reply via email to

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