AWK Tool Introduction

zhaozj2021-02-16  108

Summary

The AWK utility has its own self-contained language, not only in Linux is also one of the most powerful data processing engines in any environment. The biggest feature of this programming and data operation language (its name to its founder ALFRED AHO, Peter Weinberger and Brian Kernighan last name) depends on the knowledge you have. It allows you to create short programs that read input files, sorted by sorting, processing data, perform calculations for input, and generate reports, and countless functions. (2004-07-19 21:39:24)

-------------------------------------------------- ------------------------------

By lanf, source: http://otn.racle.com/global/cn/pub/articles/dulaney_awk.html

Author Emmett Dulaney

Are you learning Linux? This article describes the very useful AWK text operating tools, very valuable.

The AWK utility has its own self-contained language, not only in Linux is also one of the most powerful data processing engines in any environment. The biggest feature of this programming and data operation language (its name to its founder ALFRED AHO, Peter Weinberger and Brian Kernighan last name) depends on the knowledge you have. It allows you to create short programs that read input files, sorted by sorting, processing data, perform calculations for input, and generate reports, and countless functions.

What is AWK?

Saturm, AWK is a programming language tool for processing text. The language of the AWK utility is similar to the shell programming language, although AWK has a syntax that is completely its own. When you originally created AWK, its purpose is to use for text processing, and the basis of this language is that a series of instructions are performed as long as there is a mode match in the input data. This utility scans each row in the file to find the mode that matches the content given in the command line. If you find the matching content, the next programming step is performed. If you can't find the match, continue to process the next line.

Although the operation may be complicated, the syntax of the command is always:

awk '{pattern action}' {filenames}

The Pattern represents the contents of the AWK lookup in the data, and Action is a series of commands performed when the match is found. Praggies ({}) do not need to appear in the program, but they are used to group a series of instructions based on a particular mode.

Understand field

A utility divides each input line into records and fields. Record is a single-line input, and each record contains several fields. The default field separator is a space or a tab, and the recorded separator is a wrap. While watching tabs and spaces are viewed by default (multiple spaces still as a separator), the separator can be changed from space to any other characters.

To make a demonstration, check the staff list file saved as EMP_NAMES:

46012 Dulaney Evan Mobile Al

46013 Durham Jeff Mobile Al

46015 Steen Bill Mobile Al

46017 Feldman Evan Mobile Al

46018 Swim Steve Unknown Al

46019 Bogue Robert Phoenix AZ

46021 June Micah Phoenix AZ

46022 Kane Sheryl Unknown Ar

46024 Wood William Muncie in

46026 Fergus Sarah Muncie In46027 Buck Sarah Muncie in

46029 TUTTLE BOB MUNCIE IN

When the AWK reads the input content, the entire record is assigned to the variable $ 0. Each field is separated by field separator, assigned to a variable $ 1, $ 2, $ 3, and more. One line can contain countless fields in nature, access each field through the field number. Therefore, command

Awk '{Print $ 1, $ 2, $ 3, $ 4, $ 5}' Names

The print output will result

46012 Dulaney Evan Mobile Al

46013 Durham Jeff Mobile Al

46015 Steen Bill Mobile Al

46017 Feldman Evan Mobile Al

46018 Swim Steve Unknown Al

46019 Bogue Robert Phoenix AZ

46021 June Micah Phoenix AZ

46022 Kane Sheryl Unknown Ar

46024 Wood William Muncie in

46026 Fergus Sarah Muncie in

46027 Buck Sarah Muncie in

46029 TUTTLE BOB MUNCIE IN

An important thing that is worth noting is that the AWK interprets five fields separated by spaces, but when it prints the display, there is only one space between each field. With the function of specifying a unique number for each field, you can select only a specific field. For example, only the name of each record is printed, just select the second and third fields:

$ awk '{Print $ 2, $ 3}' EMP_NAMES

Dulaney Evan

DURHAM JEFF

Steen Bill

Feldman Evan

Swim Steve

Bogue Robert

June Micah

Kane Sheryl

Wood William

Fergus sarah

Buck Sarah

TUTTLE BOB

$

You can also specify print fields in any order, regardless of how they exist in the record. Therefore, only the name field is required, and the order is reversed, first display the name and then display the last name:

$ awk '{Print $ 3, $ 2}' EMP_NAMES

Evan Dulaney

Jeff durham

Bill Steen

Evan Feldman

Steve Swim

Robert Bogue

Micah June

Sheryl Kane

William Wood

Sarah Fergus

Sarah Buck

Bob Tuttle

$

Mode of use

By containing a pattern that must be matched, you can choose to operate on a specific record instead of all records. The simplest form of pattern match is a search, where the item to match is included in the slash (/ pattern /). For example, only the previous operations on those who live in Alabama:

$ awk '/ al / {Print $ 3, $ 2}' EMP_NAMES

Evan Dulaney

Jeff durham

Bill Steen

Evan Feldman

Steve Swim

$

If you do not specify a field to be printed, you will print the entire matching entry:

$ awk '/ al /' EMP_NAMES

46012 Dulaney Evan Mobile Al

46013 Durham Jeff Mobile Al

46015 Steen Bill Mobile Al

46017 Feldman Evan Mobile Al

46018 Swim Steve Unknown Al $

Multiple commands to the same data set can be separated by a semicolon (;). For example, print your name in a row, and print the city and the state name in another line:

$ awk '/ al / {Print $ 3, $ 2; Print $ 4, $ 5}' EMP_NAMES

Evan Dulaney

Mobile al

Jeff durham

Mobile al

Bill Steen

Mobile al

Evan Feldman

Mobile al

Steve Swim

Unknown Al

$

If you do not use a semicolon (Print $ 3, $ 2, $ 4, $ 5), all content will be displayed in the same line. On the other hand, if two printed statements are given, completely different results are generated:

$ awk '/ al / {Print $ 3, $ 2} {Print $ 4, $ 5}' EMP_NAMES

Evan Dulaney

Mobile al

Jeff durham

Mobile al

Bill Steen

Mobile al

Evan Feldman

Mobile al

Steve Swim

Unknown Al

Phoenix az

Phoenix az

Unknown Ar

Muncie in

Muncie in

Muncie in

Muncie in

$

Fields three and fields are given only when they find Al in the list. However, the field four and field fifth is unconditional and always print them. Only commands in the first set of curly brackets work on the command (/ al /) adjacent to the front.

The result is very inconvenient to read, you can make it slightly clearer. First, insert a space and comma between the city and the state. Then, place an empty line after each line of display:

$ awk '/ al / {Print $ 3, $ 2; Print $ 4, "$ 5" / n "}' EMP_NAMES

Evan Dulaney

Mobile, Al

Jeff durham

Mobile, Al

Bill Steen

Mobile, Al

Evan Feldman

Mobile, Al

Steve Swim

Unknown, Al

$

Between the fourth and fifth fields, add a comma and a space (between quasiograms), behind the fifth field, print a newline (/ N). You can also use all special characters that can be used in the echo command in the AWK print statement, including:

/ N (Renewal)

/ t (tabulation)

/ b (back)

/ f (paper feed)

/ r (Enter)

Therefore, to read all five originally separated fields separated by tab, and also print them with tabs, you can program the following

$ awk '{print $ 1 "/ t" $ 2 "/ t" $ 3 "/ t" $ 4 "/ t" $ 5}' EMP_NAMES

46012 Dulaney Evan Mobile Al

46013 Durham Jeff Mobile Al

46015 Steen Bill Mobile Al

46017 Feldman Evan Mobile Al

46018 Swim Steve Unknown Al

46019 Bogue Robert Phoenix AZ

46021 June Micah Phoenix AZ

46022 Kane Sheryl Unknown Ar

46024 Wood William Muncie in

46026 Fergus Sarah Muncie In46027 Buck Sarah Muncie in

46029 TUTTLE BOB MUNCIE IN

$

By continuously seting multiple standards and separated by the pipe (|) symbol, you can search multiple models at a time:

$ awk '/ al | IN /' EMP_NAMES

46012 Dulaney Evan Mobile Al

46013 Durham Jeff Mobile Al

46015 Steen Bill Mobile Al

46017 Feldman Evan Mobile Al

46018 Swim Steve Unknown Al

46024 Wood William Muncie in

46026 Fergus Sarah Muncie in

46027 Buck Sarah Muncie in

46029 TUTTLE BOB MUNCIE IN

$

This can find a matching record of each Alabama and Indiana residents. But when I tried to find someone living in Arizona, there was a problem:

$ awk '/ ar /' EMP_NAMES

46019 Bogue Robert Phoenix AZ

46021 June Micah Phoenix AZ

46022 Kane Sheryl Unknown AZ

46026 Fergus Sarah Muncie in

46027 Buck Sarah Muncie in

$

Employees 46026 and 46027 have not lived in Arizona; but their names include the sequence of characters in the search. Remember to match mode matching in the AWK, such as grep, sed, or most other Linux / UNIX commands, which will match anywhere in the record (row) unless otherwise specified. To solve this problem, the search must be linked to a specific field. By using the transcription (?) And the description of the specific field, this can be achieved, as shown in the following example:

$ awk '$ 5? / ar /' EMP_NAMES

46019 Bogue Robert Phoenix AZ

46021 June Micah Phoenix AZ

46022 Kane Sheryl Unknown AZ

$

The corresponding symbol of the transmissive (indicating match) is a single-character number (!?) With an exclamation mark. These character notification programs, if the search sequence does not appear in the specified field, identify all the lines matching the search sequence:

$ awk '$ 5!? / ar /' names

46012 Dulaney Evan Mobile Al

46013 Durham Jeff Mobile Al

46015 Steen Bill Mobile Al

46017 Feldman Evan Mobile Al

46018 Swim Steve Unknown Al

46024 Wood William Muncie in

46026 Fergus Sarah Muncie in

46027 Buck Sarah Muncie in

46029 TUTTLE BOB MUNCIE IN

$

In this case, all rows-including two Sarah entries will be displayed in the fifth field, which does include Ar, but is in the third field instead of the fifth field.

Praggies and field separators

Bracket characters play a very important role in the awk command. The operation between brackets is pointed out to what will happen and when it happened. When only one pair of parenthesis:

{Print $ 3, $ 2}

All operations between parentheses occur. When using more than a pair of parentheses:

{Print $ 3} {Print $ 2}

Execute the first set of commands, execute the second set command after the command is completed. Note the difference between the following list:

$ awk '{Print $ 3, $ 2}' Names

Evan Dulaney

Jeff durham

Bill Steen

Evan Feldman

Steve Swim

Robert Bogue

Micah June

Sheryl Kane

William Wood

Sarah Fergus

Sarah Buck

Bob Tuttle

$

$ awk '{Print $ 3} {Print $ 2}' Names

Evan

Dulaney

Jeff

DURHAM

Bill

Steen

Evan

Feldman

Steve

SWIM

Robert

Bogue

MICAH

June

Sheryl

Kane

William

Wood

Sarah

Fergus

Sarah

Buck

Bob

TUTTLE

$

To use multiple sets of parentheses to repeat the lookup, execute commands in the first group until the completion; then processes the second set of commands. If there is a third set of commands, then execute it after the second set of commands are completed, and so on. In the generated printout, there are two separate print commands, so the first command is executed, then the second command is executed, thus causing each entry to be displayed in two rows instead of a row.

The field separator distinguishes between two fields is not necessarily spaced; it can be any identifiable character. To make a demonstration, assuming that the EMP_NAMES file uses a colon rather than tabs to separate fields:

$ CAT EMP_NAMES

46012: Dulaney: Evan: Mobile: Al

46013: DURHAM: JEFF: Mobile: Al

46015: Steen: Bill: Mobile: Al

46017: Feldman: Evan: Mobile: Al

46018: SWIM: Steve: Unknown: Al

46019: Bogue: Robert: Phoenix: AZ

46021: June: MICAH: Phoenix: AZ

46022: Kane: SHERYL: Unknown: Ar

46024: WOOD: WILLIAM: MUNCIE: in

46026: FERGUS: Sarah: Muncie: in

46027: BUCK: Sarah: Muncie: in

46029: TUTTLE: BOB: MUNCIE: in

$

If you try to print a surname by specifying the second field you want

$ awk '{print $ 2}' EMP_NAMES

You will finally get twelve blank lines. Because there is no space in the file, there is no confusturable field except the first field. To solve this problem, you must notify AWK is another character other than spaces as a separator. There are two ways to notify AWK to deliver the new field separator: Use the command line parameter -f, or specify the variable FS in the program. The effects of the two methods are the same, only one exception, as shown in the following example:

$ awk '{fs = ":} {print $ 2}' EMP_NAMES

DURHAM

Steen

Feldman

SWIM

Bogue

June

Kane

Wood

Fergus

Buck

TUTTLE

$

$ awk -f: '{Print $ 2}' EMP_NAMES

Dulaney

DURHAM

Steen

Feldman

SWIM

Bogue

June

Kane

Wood

Fergus

Buck

TUTTLE

$

In the first command, the first record returns an incorrect space line, while the other results are correct. The field separator is identified until the second record is read and executed correctly. This disadvantage can be corrected by using a begin statement (detailed later). The function of -f is very similar to Begin, and the first record is read correctly and executed as required. At the beginning of this article I mentioned that the default display / output field separator is space. This feature can be changed in the program by using the output field separator (OFS) variable. For example, to read a file (separated by colon) and display it in a short line, the command is

$ awk -f ":" {OFS = "-" {Print $ 1, $ 2, $ 3, $ 4, $ 5} 'EMP_NAMES

46012-Dulaney-Evan-Mobile-Al

46013-DURHAM-JEFF-Mobile-Al

46015-Steen-Bill-Mobile-Al

46017-Feldman-Evan-Mobile-Al

46018-SWIM-Steve-Unknown-al

46019-Bogue-Robert-Phoenix-AZ

46021-June-Micah-Phoenix-AZ

46022-Kane-sheryl-unknown-ar

46024-WOOD-WILLIAM-MUNCIE-IN

46026-Fergus-Sarah-Muncie-in

46027-Buck-Sarah-Muncie-in

46029-TUTTLE-BOB-MUNCIE-IN

$

FS and OFS are (input) field separators and output field separators that are just a pair of variables that can be used in the AWK utility. For example, to be numbered per line in printing, you can use NR variables in the following manner:

$ awk -f ":" '{Print NR, $ 1, $ 2, $ 3}' EMP_NAMES

1 46012 Dulaney Evan

2 46013 Durham Jeff

3 46015 Steen Bill

4 46017 Feldman Evan

5 46018 Swim Steve

6 46019 Bogue Robert

7 46021 June MICAH

8 46022 Kane Sheryl

9 46024 WOOD WILLIAM

10 46026 Fergus Sarah

11 46027 Buck Sarah

12 46029 TUTTLE BOB

$

Find all the staff numbers in 46012 and 46015:

$ awk -f ":" '/ 4601 [2-5] /' EMP_NAMES

46012 Dulaney Evan Mobile Al

46013 Durham Jeff Mobile Al

46015 Steen Bill Mobile Al

$

Add text

Text can be added to the display in the same way as adding control sequences or other characters. For example, to change the separator from the space to a colon, the command is

AWK '{Print $ 1: "$ 2": "$ 3": "$ 4": "$ 5}' EMP_NAMES> New_EMP_NAMES

In this case, the character (:) is included in the quotation mark ("/"), which is added to each field. The value between quotation marks can be anything. For example, create a look similar to the display of employees living in Alabama:

$ awk '$ 5 ~ / al / {print "Name:" $ 2 "," $ 3 "/ ncity-state:

"$ 4", "$ 5" / n "} 'EMP_NAMESNAME: Dulaney, Evan

City-state: Mobile, Al

Name: durham, jeff

City-state: Mobile, Al

Name: Steen, Bill

City-state: Mobile, Al

Name: Feldman, Evan

City-state: Mobile, Al

Name: SWIM, Steve

City-state: unknown, al

$

Mathematical operation

In addition to providing text functions, AWK also provides full range of arithmetic operators, including the following symbols:

Add numbers

- Less

* Multiplied

/ Division

^ Execute Index Operation

% Provide a model

plus the variable value

= Assign the results of other operations to the variable

- minus variables

- = Assign the result of subtraction operation to variables

* = Results of allocation multiplication

/ = Result of distributing division operation

% = Allocate Sample Operation Results

For example, assume that there is the following files on your machine, list the items in the hardware store in detail:

$ Cat Inventory

Hammers 5 7.99

DRILLS 2 29.99

Punches 7 3.59

Drifts 2 4.09

BITS 55 1.19

Saws 123 14.99

Nails 800.19

Screws 80.29

BRADS 100 .24

$

The first business order is by multiplying the value of the second field (number) by the value of the third field (price), calculates the inventory value of each item:

$ awk '{Print $ 1, "Qty:" $ 2, "Price:" $ 3, "Total:" $ 2 * $ 3}' Inventory

Hammers Qty: 5 Price: 7.99 Total: 39.95

DRILLS Qty: 2 Price: 29.99 Total: 59.98

Punches QTY: 7 Price: 3.59 Total: 25.13

Drifts Qty: 2 Price: 4.09 Total: 8.18

BITS Qty: 55 Price: 1.19 Total: 65.45

Saws Qty: 123 Price: 14.99 Total: 1843.77

Nails Qty: 800 Price: .19 Total: 152

Screws Qty: 80 Price: .29 Total: 23.2

BRADS Qty: 100 Price: .24 Total: 24

$

If these lines itself is not important, you just want to determine how many items in the store, you can assign a normal variable, increase the number of items in each record:

$ awk '{x = x $ 2} {print x}' inventory

5

Seduce

14

16

71

194

994

1074

1174

$

According to this data, there are 1174 items in the store. When executed for the first time, the variable X does not value, so it uses the value of the first line second field. When executed for the second execution, it retains the value of the first row and adds the value of the second line, so that the cumulative total is reached.

The same process can be applied to determine the total value of existing stocks:

$ awk '{x = x ($ 2 * $ 3)} {print x}' inventory

39.95

99.93

125.06

133.24

198.69

2042.46

2194.46

2217.66

2241.66

$

Therefore, the value of 1174 items is $ 2,241.66. Although this process can obtain a total value, it is poor and needs to be processed into actual reports. Using some additional items, it is easy to make the display more neat:

$ awk '{x = x ($ 2 * $ 3)} {Print $ 1, "Qty:" $ 2, "Price:" $ 3, "Total:" $ 2 * $ 3, "BAL:" x}' Inventory

Hammers Qty: 5 Price: 7.99 Total: 39.95 Bal: 39.95

Drills Qty: 2 Price: 29.99 Total: 59.98 BAL: 99.93

Punches QTY: 7 Price: 3.59 Total: 25.13 Bal: 125.06

Drifts Qty: 2 Price: 4.09 Total: 8.18 Bal: 133.24

Bits Qty: 55 Price: 1.19 Total: 65.45 BAL: 198.69

Saws Qty: 123 Price: 14.99 Total: 1843.77 Bal: 2042.46

Nails Qty: 800 Price: .19 Total: 152 Bal: 2194.46

Screws Qty: 80 Price: .29 Total: 23.2 Bal: 2217.66

BRADS Qty: 100 Price: .24 Total: 24 BAL: 2241.66

$

This process provides a list of each record while assigning the total value to the inventory value, and maintaining the operation balance of the store asset.

Begin and End

Use the begin and end statements to specify separately before or after processing actual start. The Begin statement is most commonly used to establish a variable or display title. On the other hand, the END statement can be used to continue processing after the end of the program.

In the previous example, the total value of the item is generated using the following routines:

awk '{x = x ($ 2 * $ 3)} {print x}' inventory

This routine shows each row in the file when running total. There is no other way to specify it without making printing in each row, causing it to never print. However, using the END statement to avoid this question:

$ awk '{x = x ($ 2 * $ 3)} end {print "Total value of inventory:" x}' inventory

Total Value of Inventory: 2241.66

$

Variable X is defined, it processes each line; however, no display is generated before all processing is complete. Although it can be used as a stand-alone routine, it can also be placed to the previous code list, add more information and generate more complete reports:

$ awk '{x = x ($ 2 * $ 3)} {Print $ 1, "Qty:" $ 2, "Price:

"$ 3," Total: "$ 2 * $ 3} End {print" Total Value of Inventory: "x} 'inventory

Hammers Qty: 5 Price: 7.99 Total: 39.95

DRILLS Qty: 2 Price: 29.99 Total: 59.98

Punches QTY: 7 Price: 3.59 Total: 25.13

Drifts Qty: 2 Price: 4.09 Total: 8.18

BITS Qty: 55 Price: 1.19 Total: 65.45

Saws Qty: 123 Price: 14.99 Total: 1843.77nails Qty: 800 Price: .19 Total: 152

Screws Qty: 80 Price: .29 Total: 23.2

BRADS Qty: 100 Price: .24 Total: 24

Total Value of Inventory: 2241.66

$

The begin command is the same as the work mode of End, but it has established items that need to be made before completing other work. The most common purpose of this process is to create a header of the report. The syntax of this routine is similar to

$ awk 'begin {print "item quantity price total"}'

Enter, output, and source files

The awk tool can read its input from the file. As you do before this, it can also get input from the output of other commands. E.g:

$ sort emp_names | awk '{Print $ 3, $ 2}'

The input of the awk command is the output of the sort operation. In addition to sort, you can also use any other Linux commands - such as GREP. This process allows you to perform other operations on files before leaving the selected field.

Similar to the interpreter, the AWK uses the output and modirective operators> and >> put it in the file instead of the standard output device. The effects of these symbols are similar to their corresponding symbols in the interpreter, so> Create a file when there is no file, and >> Add to the tail of the existing file. Please see the following example:

$ awk '{print nr, $ 1)> "/ tmp / filez"}' EMP_NAMES

$ CAT / TMP / FILEZ

1 46012

2 46013

3 46015

4 46017

5 46018

6 46019

7 46021

8 46022

9 46024

10 46026

11 46027

12 46029

$

Check the syntax of this statement, you will see the output reigning is done after the print statement is completed. The file name must be included in the quotation marks, otherwise it is just an unmetuted AWK variable, and the instruction is coupled to the AWK. (If you use the re-symbol correctly, AWK can't understand that the symbol means "re-direction" or a relational operator.)

Output to the pipe in the AWK is similar to the same operations implemented in the interpreter. To send the output of the print command to the pipe, you can add the piping symbol and the name of the command after printing the command, as shown below:

$ awk '{print $ 2 | "sort"}' EMP_NAMES

Bogue

Buck

Dulaney

DURHAM

Feldman

Fergus

June

Kane

Steen

SWIM

TUTTLE

Wood

$

This is the case where the output is changed, and the command must be included in the quotation mark, and the name of the pipe is the name of the executed command.

The command used by awk can come from two places. First, you can specify them in the command line, as shown in the example. Second, they can be provided by the source file. If this is the case, this situation will be warned to the AWK through the -f option. The demo is as follows:

$ cat awklist

{Print $ 3, $ 2}

{Print $ 4, $ 5, "/ N"}

$

$ awk -f awklist EMP_NAMES

Evan Dulaney

Mobile al

Jeff durham

Mobile al

Bill Steen

Mobile al

Evan Feldman

Mobile al

Steve Swim

Unknown Al

Robert Boguephoenix AZ

Micah June

Phoenix az

Sheryl Kane

Unknown Ar

William Wood

Muncie in

Sarah Fergus

Muncie in

Sarah Buck

Muncie in

Bob Tuttle

Muncie in

$

Note that no single quotes are used anywhere in the source file or when you call it in the command line. Single quotes are only used to distinguish commands and file names in the command line.

If a simple output cannot handle the complex information you need in your program, you can try the more complex output obtained by the printf command, its syntax is

Printf (Format, Value, Value ...)

This syntax is similar to the Printf command in the C language, and the specifications of the format are the same. This format can be defined by inserting a definition of how to print a value. The format specification contains a% of the letter with letters. Similar to the print command, Printf does not have to be included in parentheses, but it can be considered to use parentheses to be a good habit.

The following table lists the various specifications provided by the printf command.

Specifications

% C prints a single ASCII character

% D print decimal

% e print digital scientific count

% F print floating point

% g Print% e or% f; two ways are shorter

% o Print unsigned octal number

S prints a ASCII string

% x Print unsigned hexadecimal number

%% printing percent sign; do not perform conversion

Some additional formatting parameters can be provided between% and characters. These parameters further improve the value of the value:

Parameter Description

- Align the expression in the field

Width is supplemented to the specified width as needed (the preamble zero uses zero to make fields)

.prec decimal point on the maximum string width or maximum number of numbers

The Printf command can control and convert the value from one format to another. When the value of the print variable is required, simply provide a specification, indicating how the printf prints information (usually included in double quotes). Variables that must be passed to PrINTF include a specification parameter; if there is a small parameter, the Printf does not print all values.

Handling error

The way the AWK tool report has occurred is annoyed. An error will hinder any operation, the error message provided is very mixed:

awk: Syntax Error Near Line 2

awk: bailing out ner line 2

You may take a few hours to view the second line, trying to find out why it hinders the program to run; this is a powerful argument that supports the use of the source file.

Remember that two rules can help you avoid syntax errors:

1. Make sure the command is in parentheses, and parentheses is in single quotes. No one of these characters must cause the program to fail.

2. The search command needs to be between the slash. To find out the employee living in Indiana, you must use "/ in /" instead of "in".

in conclusion

Although AWK completely represents additional meaning, it should be the initial abbreviation of the administrator smart toolkit. With SED, the AWK utility is one of the most powerful and flexible tools owned by Linux administrators. By understanding some of their language, you can open up a field that simplifies tasks, otherwise these tasks will be very time and difficult.

转载请注明原文地址:https://www.9cbs.com/read-10269.html

New Post(0)