help-gawk
[Top][All Lists]
Advanced

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

awk BEGIN END syntax


From: Michael Herdman
Subject: awk BEGIN END syntax
Date: Sun, 23 Jun 2024 12:03:04 +0200
User-agent: Mozilla Thunderbird

Hi,
How can I resolve the following problem? I have an infile with two tab-separated columns the first of which contains two words separated by a single space:

a b    g
c d    h
e f    i

When I run the following awk command, in which the quotation marks are escaped to retain them:

awk 'BEGIN {print "<tr><td class=\"Col1_col\">"$1"</td><td class=\"Col2_col\">"$2"</td></tr>"}' infile > outfile

I expect the outfile to contain:

<tr><td class="Col1_col"a b></td><td class="Col2_col"g></td></tr>
but $1 and $2 are not returned.

I know that the BEGIN statement has to be followed somewhere by an END statement, but I do not see where to put it or what action to assign to it.

--
Michael Herdman
Institut Pasteur (retired)
Visit the cyanobacterial reference phylogeny site:
http://cyanophylogeny.scienceontheweb.net/




reply via email to

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