text
stringlengths
1
1k
In a format similar to C, function definitions consist of the keyword codice_22, the function name, argument names and the function body. Here is an example of a function.
function add_three (number) {
This statement can be invoked as follows:
print add_three(36) # Outputs 39
Functions can have variables that are in the local scope. The names of these are added to the end of the argument list, though values for these should be omitted when calling the function. It is convention to add some whitespace in the argument list before the local variables, to indicate where the parameters end and the local variables begin.
Here is the customary "Hello, World!" program written in AWK:
print "Hello, world!"
Print lines longer than 80 characters.
Print all lines longer than 80 characters. Note that the default action is to print the current line.
Count words in the input and print the number of lines, words, and characters (like wc):
chars += length + 1 # add one to account for the newline character at the end of each record (line)
As there is no pattern for the first line of the program, every line of input matches by default, so the increment actions are executed for every line. Note that codice_23 is shorthand for codice_24.
"s" is incremented by the numeric value of "$NF", which is the last word on the line as defined by AWK's field separator (by default, white-space). "NF" is the number of fields in the current line, e.g. 4. Since "$4" is the value of the fourth field, "$NF" is the value of the last field in the line regardless of how many fields this line has, or whether it has more or fewer fields than surrounding lines. $ is actually a unary operator with the highest operator precedence. (If the line has no fields, then "NF" is 0, "$0" is the whole line, which in this case is empty apart from possible white-space, and so has the numeric value 0.)
At the end of the input the "END" pattern matches, so "s" is printed. However, since there may have been no lines of input at all, in which case no value has ever been assigned to "s", it will by default be an empty string. Adding zero to a variable is an AWK idiom for coercing it from a string to a numeric value. (Concatenating an empty string is to coerce from a number to a string, e.g. "s """. Note, there's no operator to concatenate strings, they're just placed adjacently.) With the coercion the program prints "0" on an empty input, without it, an empty line is printed.
Match a range of input lines.
The action statement prints each line numbered. The printf function emulates the standard C printf and works similarly to the print command described above. The pattern to match, however, works as follows: "NR" is the number of records, typically lines of input, AWK has so far read, i.e. the current line number, starting at 1 for the first line of input. "%" is the modulo operator. "NR % 4 == 1" is true for the 1st, 5th, 9th, etc., lines of input. Likewise, "NR % 4 == 3" is true for the 3rd, 7th, 11th, etc., lines of input. The range pattern is false until the first part matches, on line 1, and then remains true up to and including when the second part matches, on line 3. It then stays false until the first part matches again on line 5.
Thus, the program prints lines 1,2,3, skips line 4, and then 5,6,7, and so on. For each line, it prints the line number (on a 6 character-wide field) and then the line contents. For example, when executed on this input:
The previous program prints:
Printing the initial or the final part of a file.
As a special case, when the first part of a range pattern is constantly true, e.g. "1", the range will start at the beginning of the input. Similarly, if the second part is constantly false, e.g. "0", the range will continue until the end of input. For example,
/^--cut here--$/, 0
prints lines of input from the first line matching the regular expression "^--cut here--$", that is, a line containing only the phrase "--cut here--", to the end.
Calculate word frequencies.
Word frequency using associative arrays:
for (i=1; i<=NF; i++)
words[tolower($i)]++
The BEGIN block sets the field separator to any sequence of non-alphabetic characters. Note that separators can be regular expressions. After that, we get to a bare action, which performs the action on every input line. In this case, for every field on the line, we add one to the number of times that word, first converted to lowercase, appears. Finally, in the END block, we print the words with their frequencies. The line
creates a loop that goes through the array "words", setting "i" to each "subscript" of the array. This is different from most languages, where such a loop goes through each "value" in the array. The loop thus prints out each word followed by its frequency count. codice_25 was an addition to the One True awk (see below) made after the book was published.
Match pattern from command line.
This program can be represented in several ways. The first one uses the Bourne shell to make a shell script that does everything. It is the shortest of these methods:
awk '/'"$pattern"'/ { print FILENAME ":" $0 }' "$@"
The codice_26 in the awk command is not protected by single quotes so that the shell does expand the variable but it needs to be put in double quotes to properly handle patterns containing spaces. A pattern by itself in the usual way checks to see if the whole line (codice_27) matches. codice_16 contains the current filename. awk has no explicit concatenation operator; two adjacent strings concatenate them. codice_27 expands to the original unchanged input line.
There are alternate ways of writing this. This shell script accesses the environment directly from within awk:
awk '$0 ~ ENVIRON["pattern"] { print FILENAME ":" $0 }' "$@"
This is a shell script that uses codice_30, an array introduced in a newer version of the One True awk after the book was published. The subscript of codice_30 is the name of an environment variable; its result is the variable's value. This is like the getenv function in various standard libraries and POSIX. The shell script makes an environment variable codice_32 containing the first argument, then drops that argument and has awk look for the pattern in each file.
codice_6 checks to see if its left operand matches its right operand; codice_34 is its inverse. Note that a regular expression is just a string and can be stored in variables.
The next way uses command-line variable assignment, in which an argument to awk can be seen as an assignment to a variable:
awk '$0 ~ pattern { print FILENAME ":" $0 }' "pattern=$pattern" "$@"
Or You can use the "-v var=value" command line option (e.g. "awk -v pattern="$pattern" ...").
Finally, this is written in pure awk, without help from a shell or without the need to know too much about the implementation of the awk script (as the variable assignment on command line one does), but is a bit lengthy:
for (i = 1; i < ARGC; i++) # remove first argument
ARGV[i] = ARGV[i + 1]
if (ARGC == 1) { # the pattern was the only thing, so force read from standard input (used by book)
The codice_4 is necessary not only to extract the first argument, but also to prevent it from being interpreted as a filename after the codice_4 block ends. codice_37, the number of arguments, is always guaranteed to be ≥1, as codice_38 is the name of the command that executed the script, most often the string codice_39. Also note that codice_40 is the empty string, codice_41. codice_42 initiates a comment that expands to the end of the line.
Note the codice_43 block. awk only checks to see if it should read from standard input before it runs the command. This means that
only works because the fact that there are no filenames is only checked before codice_44 is run! If you explicitly set codice_37 to 1 so that there are no arguments, awk will simply quit because it feels there are no more input files. Therefore, you need to explicitly say to read from standard input with the special filename codice_46.
Self-contained AWK scripts.
On Unix-like operating systems self-contained AWK scripts can be constructed using the shebang syntax.
For example, a script that sends the content of a given file to standard output may be built by creating a file named codice_47 with the following content:
It can be invoked with: codice_48
The codice_49 tells awk that the argument that follows is the file to read the AWK program from, which is the same flag that is used in sed. Since they are often used for one-liners, both these programs default to executing a program given as a command-line argument, rather than a separate file.
Versions and implementations.
AWK was originally written in 1977 and distributed with Version 7 Unix.
In 1985 its authors started expanding the language, most significantly by adding user-defined functions. The language is described in the book "The AWK Programming Language", published 1988, and its implementation was made available in releases of UNIX System V. To avoid confusion with the incompatible older version, this version was sometimes called "new awk" or "nawk". This implementation was released under a free software license in 1996 and is still maintained by Brian Kernighan (see external links below).
Old versions of Unix, such as UNIX/32V, included codice_50, which converted AWK to C. Kernighan wrote a program to turn awk into C++; its state is not known.
In Nordic mythology, Asgard (Old Norse: Ásgarðr ; "enclosure of the Æsir") is a location associated with the gods. It appears in a multitude of Old Norse sagas and mythological texts. It is described as the fortified home of the Æsir gods, often associated with gold imagery. Many of the best-known Nordic gods are Æsir or live in Asgard such as Odin, Thor, Loki, and Baldr.
The word "Ásgarðr" is a compound formed from ("god") and ("enclosure"). Possible anglicisations include: Ásgarthr, Ásgard, Ásegard, Ásgardr, Asgardr, Ásgarth, Asgarth, Esageard, and Ásgardhr.
Asgard is named twice in Eddic poetry. The first case is in "Hymiskviða", when Thor and Týr journey from Asgard to Hymir's hall to obtain a cauldron large enough to brew beer for a feast for Ægir and the gods. The second instance is in "Þrymskviða" when Loki is attempting to convince Thor to dress up as Freyja in order to get back Mjölnir by claiming that without his hammer to protect them, jötnar would soon be living in Asgard.
"Grímnismál" contains among its cosmological descriptions, a number of abodes of the gods, such as Álfheim, Nóatún and Valhall, which some scholars have identified as being in Asgard. It is to be noted, however, that Asgard is not mentioned at any point in the poem. Furthermore, "Völuspá" references Iðavöllr, one of the most common meeting places of Æsir gods, which in "Gylfaginning", Snorri locates in the centre of Asgard.
The Prose Edda's euhemeristic prologue portrays the Æsir gods as people that travelled from the East to northern territories. According to Snorri, Asgard represented the town of Troy before Greek warriors overtook it. After the defeat, Trojans moved to northern Europe, where they became a dominant group due to their "advanced technologies and culture". Eventually, other tribes began to perceive the Trojans and their leader Trór (Thor in Old Norse) as gods.
In "Gylfaginning", Snorri Sturluson describes how during the creation of the world, the gods made the earth and surrounded it with the sea. They made the sky from the skull of Ymir and settled the on the shores of the earth. They set down the brows of Ymir, forming Midgard, and in the centre of the world they built Asgard, which he identifies as Troy:
After Asgard is made, the gods then built a hof named Glaðsheimr at Iðavöllr, in the centre of the burg, with a high seat for Odin and twelve seats for other gods. It is described as like gold both on the inside and the outside, and as the best of all buildings in the world. They also built Vingólf for the female gods, which is described as both a hall and a hörgr, and a forge with which they crafted objects from gold. After Ragnarök, some gods such as Váli and Baldr will meet at Iðavöllr where Asgard once stood and discuss matters together. There they will also find in the grass the golden chess pieces that the Æsir had once owned.
In "Gylfaginning", the central cosmic tree Yggdrasil is described as having three roots that hold it up; one of these goes to the Æsir, which has been interpreted as meaning Asgard. In "Grímnismál", this root instead reaches over the realm of men. The bridge Bifröst is told to span from the heavens to the earth and over it the Æsir cross each day to hold council beneath Yggdrasil at the Urðarbrunnr. Based on this, Bifröst is commonly interpreted as the bridge to Asgard.
Asgard is mentioned briefly throughout "Skáldskaparmál" as the name for the home of the Æsir, as in "Gylfaginning". In this section, a number of locations are described as lying within Asgard including Valhalla, and in front of its doors, the golden grove Glasir. It also records a name for Thor as 'Defender of Ásgard' ().
In the "Ynglinga" saga, found in Heimskringla, Snorri describes Asgard as a city in Asia, based on a perceived, but erroneous, connection between the words for Asia and Æsir. In the opening stanzas of the Saga of the Ynglings, Asgard is the capital of Asaland, a section of Asia east of the river Tana-kvísl or Vana-Kvísl (kvísl is "arm"), which Snorri explains is the river Tanais (now Don), flowing into the Black Sea. Odin then leaves to settle in the northern part of the world and leaves his brothers Vili and Vé to rule over the city. When the euhemerised Odin dies, the account states that the Swedes believed he had returned to Asgard and would live there forever.
Interpretation and discussion.
It has been noted that the tendency to link Asgard to Troy is part of a wider European cultural practice of claiming Trojan origins for one's culture, first seen in the "Aeneid" and also featuring in Geoffrey of Monmouth's "Historia regum Britanniae" for the founding of Britain.
Depictions in popular culture.
Thor first appeared in the Marvel Universe within comic series "Journey into Mystery" in the issues #83 during August 1962. Following this release, he becomes one of the central figures in the comics along with Loki and Odin. In the Marvel Cinematic Universe, Thor and Loki make their first appearance together in the 2011 film "Thor". After that, Thor becomes a regular character in the Marvel Cinematic Universe and reappears in several films, including the "Avengers" series. Asgard becomes the central element of the film "", where it is destroyed following the Old Norse mythos. These and other Norse mythology elements also appear in video games, TV series, and books based in and on the Marvel Universe, although these depictions do not closely follow historical sources.
Asgard is an explorable realm in the video game "God of War: Ragnarök", a sequel to 2018's Norse-themed "God of War".
In the "Assassin's Creed Valhalla" video game, Asgard is featured as part of a "vision quest".
The Apollo program, also known as Project Apollo, was the United States human spaceflight program carried out by the National Aeronautics and Space Administration (NASA), which succeeded in preparing and landing the first men on the Moon from 1968 to 1972. It was first conceived in 1960 during President Dwight D. Eisenhower's administration as a three-person spacecraft to follow the one-person Project Mercury, which put the first Americans in space. Apollo was later dedicated to President John F. Kennedy's national goal for the 1960s of "landing a man on the Moon and returning him safely to the Earth" in an address to Congress on May 25, 1961. It was the third US human spaceflight program to fly, preceded by the two-person Project Gemini conceived in 1961 to extend spaceflight capability in support of Apollo.
Apollo set several major human spaceflight milestones. It stands alone in sending crewed missions beyond low Earth orbit. Apollo 8 was the first crewed spacecraft to orbit another celestial body, and Apollo 11 was the first crewed spacecraft to land humans on one.
Overall, the Apollo program returned of lunar rocks and soil to Earth, greatly contributing to the understanding of the Moon's composition and geological history. The program laid the foundation for NASA's subsequent human spaceflight capability and funded construction of its Johnson Space Center and Kennedy Space Center. Apollo also spurred advances in many areas of technology incidental to rocketry and human spaceflight, including avionics, telecommunications, and computers.
The program was named after Apollo, the Greek god of light, music, and the Sun, by NASA manager Abe Silverstein, who later said, "I was naming the spacecraft like I'd name my baby." Silverstein chose the name at home one evening, early in 1960, because he felt "Apollo riding his chariot across the Sun was appropriate to the grand scale of the proposed program".
The context of this was that the program focused at its beginning mainly on developing an advanced crewed spacecraft, the Apollo command and service module, succeeding the Mercury program. A lunar landing became the focus of the program only in 1961. Thereafter Project Gemini instead followed the Mercury program to test and study advanced crewed spaceflight technology.
Origin and spacecraft feasibility studies.
The Apollo program was conceived during the Eisenhower administration in early 1960, as a follow-up to Project Mercury. While the Mercury capsule could support only one astronaut on a limited Earth orbital mission, Apollo would carry three. Possible missions included ferrying crews to a space station, circumlunar flights, and eventual crewed lunar landings.
In July 1960, NASA Deputy Administrator Hugh L. Dryden announced the Apollo program to industry representatives at a series of Space Task Group conferences. Preliminary specifications were laid out for a spacecraft with a "mission module" cabin separate from the "command module" (piloting and reentry cabin), and a "propulsion and equipment module". On August 30, a feasibility study competition was announced, and on October 25, three study contracts were awarded to General Dynamics/Convair, General Electric, and the Glenn L. Martin Company. Meanwhile, NASA performed its own in-house spacecraft design studies led by Maxime Faget, to serve as a gauge to judge and monitor the three industry designs.
Political pressure builds.
On April 12, 1961, Soviet cosmonaut Yuri Gagarin became the first person to fly in space, reinforcing American fears about being left behind in a technological competition with the Soviet Union. At a meeting of the US House Committee on Science and Astronautics one day after Gagarin's flight, many congressmen pledged their support for a crash program aimed at ensuring that America would catch up. Kennedy was circumspect in his response to the news, refusing to make a commitment on America's response to the Soviets.
On April 20, Kennedy sent a memo to Vice President Lyndon B. Johnson, asking Johnson to look into the status of America's space program, and into programs that could offer NASA the opportunity to catch up. Johnson responded approximately one week later, concluding that "we are neither making maximum effort nor achieving results necessary if this country is to reach a position of leadership." His memo concluded that a crewed Moon landing was far enough in the future that it was likely the United States would achieve it first.
On May 25, 1961, twenty days after the first US crewed spaceflight "Freedom 7", Kennedy proposed the crewed Moon landing in a "Special Message to the Congress on Urgent National Needs":
At the time of Kennedy's proposal, only one American had flown in space—less than a month earlier—and NASA had not yet sent an astronaut into orbit. Even some NASA employees doubted whether Kennedy's ambitious goal could be met. By 1963, Kennedy even came close to agreeing to a joint US-USSR Moon mission, to eliminate duplication of effort.
With the clear goal of a crewed landing replacing the more nebulous goals of space stations and circumlunar flights, NASA decided that, in order to make progress quickly, it would discard the feasibility study designs of Convair, GE, and Martin, and proceed with Faget's command and service module design. The mission module was determined to be useful only as an extra room, and therefore unnecessary. They used Faget's design as the specification for another competition for spacecraft procurement bids in October 1961. On November 28, 1961, it was announced that North American Aviation had won the contract, although its bid was not rated as good as the Martin proposal. Webb, Dryden and Robert Seamans chose it in preference due to North American's longer association with NASA and its predecessor.
Landing humans on the Moon by the end of 1969 required the most sudden burst of technological creativity, and the largest commitment of resources ($25 billion; $ in US dollars) ever made by any nation in peacetime. At its peak, the Apollo program employed 400,000 people and required the support of over 20,000 industrial firms and universities.
On July 1, 1960, NASA established the Marshall Space Flight Center (MSFC) in Huntsville, Alabama. MSFC designed the heavy lift-class Saturn launch vehicles, which would be required for Apollo.
Manned Spacecraft Center.
It became clear that managing the Apollo program would exceed the capabilities of Robert R. Gilruth's Space Task Group, which had been directing the nation's crewed space program from NASA's Langley Research Center. So Gilruth was given authority to grow his organization into a new NASA center, the Manned Spacecraft Center (MSC). A site was chosen in Houston, Texas, on land donated by Rice University, and Administrator Webb announced the conversion on September 19, 1961. It was also clear NASA would soon outgrow its practice of controlling missions from its Cape Canaveral Air Force Station launch facilities in Florida, so a new Mission Control Center would be included in the MSC.
In September 1962, by which time two Project Mercury astronauts had orbited the Earth, Gilruth had moved his organization to rented space in Houston, and construction of the MSC facility was under way, Kennedy visited Rice to reiterate his challenge in a famous speech:
The MSC was completed in September 1963. It was renamed by the US Congress in honor of Lyndon Johnson soon after his death in 1973.
Launch Operations Center.
It also became clear that Apollo would outgrow the Canaveral launch facilities in Florida. The two newest launch complexes were already being built for the Saturn I and IB rockets at the northernmost end: LC-34 and LC-37. But an even bigger facility would be needed for the mammoth rocket required for the crewed lunar mission, so land acquisition was started in July 1961 for a Launch Operations Center (LOC) immediately north of Canaveral at Merritt Island. The design, development and construction of the center was conducted by Kurt H. Debus, a member of Wernher von Braun's original V-2 rocket engineering team. Debus was named the LOC's first Director. Construction began in November 1962. Following Kennedy's death, President Johnson issued an executive order on November 29, 1963, to rename the LOC and Cape Canaveral in honor of Kennedy.
The LOC included Launch Complex 39, a Launch Control Center, and a Vertical Assembly Building (VAB). in which the space vehicle (launch vehicle and spacecraft) would be assembled on a mobile launcher platform and then moved by a crawler-transporter to one of several launch pads. Although at least three pads were planned, only two, designated AandB, were completed in October 1965. The LOC also included an Operations and Checkout Building (OCB) to which Gemini and Apollo spacecraft were initially received prior to being mated to their launch vehicles. The Apollo spacecraft could be tested in two vacuum chambers capable of simulating atmospheric pressure at altitudes up to , which is nearly a vacuum.
Administrator Webb realized that in order to keep Apollo costs under control, he had to develop greater project management skills in his organization, so he recruited George E. Mueller for a high management job. Mueller accepted, on the condition that he have a say in NASA reorganization necessary to effectively administer Apollo. Webb then worked with Associate Administrator (later Deputy Administrator) Seamans to reorganize the Office of Manned Space Flight (OMSF). On July 23, 1963, Webb announced Mueller's appointment as Deputy Associate Administrator for Manned Space Flight, to replace then Associate Administrator D. Brainerd Holmes on his retirement effective September 1. Under Webb's reorganization, the directors of the Manned Spacecraft Center (Gilruth), Marshall Space Flight Center (von Braun), and the Launch Operations Center (Debus) reported to Mueller.
Based on his industry experience on Air Force missile projects, Mueller realized some skilled managers could be found among high-ranking officers in the U.S. Air Force, so he got Webb's permission to recruit General Samuel C. Phillips, who gained a reputation for his effective management of the Minuteman program, as OMSF program controller. Phillips's superior officer Bernard A. Schriever agreed to loan Phillips to NASA, along with a staff of officers under him, on the condition that Phillips be made Apollo Program Director. Mueller agreed, and Phillips managed Apollo from January 1964, until it achieved the first human landing in July 1969, after which he returned to Air Force duty.
Charles Fishman, in "One Giant Leap", estimated the number of people and organizations involved into the Apollo program as "410,000 men and women at some 20,000 different companies contributed to the effort".
Choosing a mission mode.
Once Kennedy had defined a goal, the Apollo mission planners were faced with the challenge of designing a spacecraft that could meet it while minimizing risk to human life, cost, and demands on technology and astronaut skill. Four possible mission modes were considered:
In early 1961, direct ascent was generally the mission mode in favor at NASA. Many engineers feared that rendezvous and docking, maneuvers that had not been attempted in Earth orbit, would be nearly impossible in lunar orbit. LOR advocates including John Houbolt at Langley Research Center emphasized the important weight reductions that were offered by the LOR approach. Throughout 1960 and 1961, Houbolt campaigned for the recognition of LOR as a viable and practical option. Bypassing the NASA hierarchy, he sent a series of memos and reports on the issue to Associate Administrator Robert Seamans; while acknowledging that he spoke "somewhat as a voice in the wilderness", Houbolt pleaded that LOR should not be discounted in studies of the question.