Find Interview Questions for Top Companies
Ques:- What is the use of string function split(string,array,separator)in AWK?
Asked In :-
Right Answer:
The `split(string, array, separator)` function in AWK is used to divide a string into substrings based on a specified separator and store those substrings in an array.
Ques:- What is the use of string function substr(string,position) in AWK?
Asked In :-
Right Answer:
The `substr(string, position)` function in AWK is used to extract a substring from a given string, starting at the specified position. The position is 1-based, meaning that the first character of the string is at position 1.
Ques:- What is the use of string function substr(string,position,max) in AWK?
Asked In :-
Right Answer:
The `substr(string, position, max)` function in AWK is used to extract a substring from a given string, starting at the specified position and up to a maximum length of characters.
Ques:- What is the use of string function index(string,search) in AWK?
Asked In :-
Right Answer:
The `index(string, search)` function in AWK returns the position of the first occurrence of the substring `search` within the string `string`. If `search` is not found, it returns 0.
Ques:- What are Trigonometric Functions in AWK?
Asked In :-
Right Answer:
In AWK, trigonometric functions include `sin(x)`, `cos(x)`, and `atan2(y, x)`, which calculate the sine, cosine, and arctangent of given angles in radians, respectively.
Ques:- How to Truncate Integers in AWK?
Asked In :-
Right Answer:
You can truncate integers in AWK by using the `int()` function. For example:

```awk
result = int(value)
```
Ques:- How to generate random numbers in AWK?
Asked In :-
Right Answer:
You can generate random numbers in AWK using the `rand()` function. For example:

```awk
awk 'BEGIN { print rand() }'
```

This will print a random number between 0 and 1. To generate a random integer within a specific range, you can use:

```awk
awk 'BEGIN { print int(rand() * (max - min + 1)) + min }'
```

Replace `min` and `max` with your desired range.
Ques:- What is the use of numeric function rand ?
Asked In :-
Right Answer:
The `rand` function in AWK generates a random floating-point number between 0 and 1.
Comments
Admin May 17, 2020

Random

Ques:- What is the use of numeric function srand ?
Asked In :-
Right Answer:
The `srand` function in AWK is used to seed the random number generator, allowing for the generation of different random numbers each time the program runs.
Comments
Admin May 17, 2020

Seed Random

Ques:- What is the use of numeric function sin ?
Asked In :-
Right Answer:
The numeric function `sin` in AWK calculates the sine of a given angle (in radians).
Comments
Admin May 17, 2020

Sine

Ques:- What is the use of numeric function sqrt ?
Asked In :-
Right Answer:
The numeric function `sqrt` is used to calculate the square root of a given number.
Comments
Admin May 17, 2020

Square Root

Ques:- What is the use of numeric function atan2?
Asked In :-
Right Answer:
The numeric function `atan2` computes the arctangent of the quotient of its two arguments, returning the angle in radians between the positive x-axis and the point (x, y) in a Cartesian coordinate system. It is useful for determining the angle of a point relative to the origin.
Comments
Admin May 17, 2020

Arctangent

Ques:- What is the use of numeric function int ?
Asked In :-
Right Answer:
The numeric function `int` in AWK is used to convert a value to an integer by truncating any decimal part.
Comments
Admin May 17, 2020

Integer

Ques:- What is the use of numeric function log ?
Asked In :-
Right Answer:
The numeric function `log` in AWK is used to calculate the natural logarithm (base e) of a given number.
Comments
Admin May 17, 2020

Logarithm

Ques:- How to exit from an awk script using the exit command?
Asked In :-
Right Answer:
You can exit from an awk script using the `exit` command followed by an optional exit status. For example:

```awk
awk '{ if ($1 == "exit") exit 0 }'
```

This will terminate the script when the first field is "exit".
Ques:- What are AWK Numerical Functions?
Asked In :-
Right Answer:
AWK numerical functions include:

1. `sin(x)` - Returns the sine of x (in radians).
2. `cos(x)` - Returns the cosine of x (in radians).
3. `atan2(y, x)` - Returns the arctangent of y/x.
4. `sqrt(x)` - Returns the square root of x.
5. `int(x)` - Returns the integer part of x.
6. `length(x)` - Returns the length of string x.
7. `rand()` - Returns a random number between 0 and 1.
8. `exp(x)` - Returns e raised to the power of x.
9. `log(x)` - Returns the natural logarithm of x.
10. `sprintf(format, ...)` - Formats and returns a string based on the specified format.
Ques:- What is the use of numeric function cos ?
Asked In :-
Right Answer:
The numeric function `cos` in AWK is used to calculate the cosine of an angle given in radians.
Comments
Admin May 17, 2020

cosine

Ques:- What is the use of numeric function exp ?
Asked In :-
Right Answer:
The numeric function `exp` in AWK is used to calculate the value of e (Euler's number, approximately 2.71828) raised to the power of a given number.
Comments
Admin May 17, 2020

Exponent

Ques:- How do you Explicit File output?
Asked In :-
Right Answer:
To explicitly output to a file in AWK, use the `>` operator followed by the filename in the `BEGIN` block. For example:

```awk
awk 'BEGIN { print "Hello, World!" > "output.txt" }'
```
Ques:- What is the use of format specifier %% ?
Asked In :-
Right Answer:
The format specifier `%%` is used in `awk` to print a literal percent sign (`%`).
Comments
Admin May 17, 2020

Literal %



The AWK category is a powerful resource for Linux administrators, DevOps engineers, and computer science students aiming to understand text processing on the command line.

Topics include:

  • Basic AWK syntax and operations

  • Pattern scanning and processing

  • Working with pipes and redirection

  • Real-time use cases in log parsing

  • AWK with shell scripting and cron jobs

  • Interview questions on AWK vs. SED vs. GREP

AmbitionBox Logo

What makes Takluu valuable for interview preparation?

1 Lakh+
Companies
6 Lakh+
Interview Questions
50K+
Job Profiles
20K+
Users