String Data Type

A string is a sequence of characters. String Data Type Adding and Concatenation using ‘+’ Adding to the two string using the ‘+’ Adding to the two string using the ‘+’ but even the numeric values here is also a string adding any numeric value to it will cause error….

String Library

String Replace This will replace the Bob with James and store it in the new variable. The variable ‘str’ will remain the same. Strip or lstrip Prefixes Parsing and Extracting Extracting data from an email ID required to search the letter ‘@’ then search the keyword ‘>’, then print the…

awk Marking keywords

Marking keywords In the following example, we mark Java keywords in a source file. The program adds and tags around each of the keywords that it recognizes. This is a basic example; it works on keywords that are separate words. It does not address the more complicated structures. We load…

awk Rock-Paper-Scissors

Rock-Paper-Scissors Rock-paper-scissors is a popular hand game in which each player simultaneously forms one of three shapes with an outstretched hand. We create this game in AWK. We play the game against the computer, which chooses its options randomly. We seed the random number generator with the srand() function. The…

awk Spell Checking

Spell checking We create an AWK program for spell checking. The script compares the words of the provided text file against a dictionary. Under the standard /usr/share/dict/words path we can find an English dictionary; each word is on a separate line. Inside the BEGIN block, we read the words from…

awk Pipes

Pipes AWK can receive input and send output to other commands via the pipe. In this case, AWK receives output from the echo command. It prints the values of last column. Here, the AWK program sends data to the wc command via the pipe. In the AWK program, we find…

awk Passing variables

Passing variables to AWK AWK has the -v option which is used to assign values to variables. For the next program, we have the general file: mygrep.awk The example simulates the grep utility. It finds the provided word and prints its line and the its starting index. (The program finds…