AWK, SEQ, XARG instance use

Detailed supplementary explanation based on https://www.cnblogs.com/wangyuebo/p/5836933.html
[[email protected] awk]# seq 10|xargs -n 2> file
[[emailprotected] awk]# seq 10 -1 1|xargs -n 2> file1
xrags -n 2 [Indicates that the number of batches is 2 each time, and the default interval is “”]
seq 10 -1 1 [It means to generate 10 numbers, output in reverse order, and the step size is 1]
[[email protected] awk]# cat file1
2 3
4 5

< div> 6 7

8 9
1 0
[[email protected] awk]# cat file |awk'{ print $1}’
1
3
5
7
9
[[email protected] awk]# awk'{print NR}’ file file1
1
2
3
4
5
6
7
8
9
10

[[email protected] awk]# awk'{print NR,FNR}’ file file1
1 1
2 2
3 3
4 4
5 5
6 1
7 2
8 3
9 4
10 5
[[email protected] awk]#
[[email protected] awk] # awk’NR==FNR{a[NR]=$1}NR!=FNR{print a[FNR],$2}’ file file1
1 93 75 57 39 1
[[email protected] awk]#
Detailed explanation of awk:
Awk is a line processor: Compared with the advantages of screen processing, there will be no memory overflow when processing large files Or the problem of slow processing, usually used to format text information
Awk processing process: each line is processed in turn, and then output
Special points:
$0 Indicates the entire current line
$1 The first field of each line
NF Field quantity variable
NR The record number of each line, multi-file records increase< /div>

FNR Similar to NR, but multi-file records are not incremented, and each file starts from 1
tab
line break

div>

FS Define the separator at BEGIN
RS The entered record separator, the default is line break (that is, the text is entered one line by line)
~ Matching, not an exact comparison compared to ==
! ~ Mismatch, inaccurate comparison
== Equal, all must be equal, exact comparison
!= Not equal, exact comparison
&& Logical AND
|| Logical OR
+ When matching, it means one or more than one
/[0-9][0- 9]+/ Two or more numbers
/[0-9][0-9]*/ One or more numbers
FILENAME file name
OFS output field separator, the default is also a space, can be changed to a tab, etc.
ORS The output record separator, the default is a newline character, that is, the processing result is also output to the screen line by line
ORS div>

-F'[:#/]’ Define three separators
[[email protected] awk]# paste file3 file4
1 9
3 7
5 5
7 3
9 1
[[email protected ] awk]# paste file3 file4|tr ” ” “”
1 9
3 7
5 5
7 3
9 1

The paste command will merge each file line by line, line by line.
-d or –delimiters=   replace tab character with specified interval character.
-s or –serial   serialize instead of parallel processing.

Detailed supplementary explanation based on https://www.cnblogs.com/wangyuebo/p/5836933.html

[[email protected] awk]# seq 10|xargs -n 2> file
[[email protected] awk]# seq 10 -1 1|xargs -n 2> file1

xrags -n 2 [means that the number of batches is 2, and the default interval is “”]
seq 10 -1 1 [means that 10 numbers are generated and output in reverse order, The step size is 1]
[[email protected] awk]# cat file1
2 3

< div> 4 5

6 7
8 9
1 0
[[email protected] awk]# cat file |awk'{print $1}’
1
3
5
7

< div> 9

[[email protected] awk]# awk'{print NR}’ file file1
1
2
3
4
5
6
7
8
9 < /div>

10
[[email protected] awk]# awk'{print NR,FNR}’ file file1
1 1

< div> 2 2

3 3
4 4
5 5
6 1
7 2 < /div>

8 3
9 4
10 5
[[emailprotected] awk]#

div>

[[email protected] awk]# awk’NR==FNR{a[NR]=$1}NR!=FNR{print a[FNR],$2}’ file file1
1 93 75 57 39 1
[[email protected] awk]#
Detailed explanation of awk:
Awk is a line processor: compared to screen processing Advantages, there will be no memory overflow or slow processing when processing large files. It is usually used to format text information.
Awk processing process: each line is processed in turn, and then output
Special points:
$0 Represents the entire current line
$1 The first field of each line
NF Field quantity variable
NR The record number of each line, multi-file records increase
FNR Similar to NR, but multi-file records do not increase, and each file starts from 1
tab character< /div>

Line break
FS Define the separator when BEGIN
RS Enter the record separator, the default is the line break (that is, the text is entered on a line by line)
~ Matching, not an exact comparison compared with ==
!~ Not matching, inaccurate comparison
== equal, must all be equal , Exact comparison
!= Not equal, Exact comparison
&&  Logic and
|| Logical or
+ When it matches, it means 1 One or more than one
/[0-9][0-9]+/ two or more numbers
/[0-9][0-9] */ One or more digits
FILENAME file name
OFS output field separator, the default is also a space, can be changed to a tab, etc.
ORS output The record separator of, the default is line break, that is, the processing result is also output to the screen line by line
-F'[:#/]’ Define three separators
[[emailprotected] awk]# paste file3 file4
1 9
3 7
5 5
7 3
9 1
[[email protected] awk]# paste file3 file4|tr ” ” “”
1 9

< div> 3 7

5 5
7 3
9 1
The paste command will put each file in line by line Ways to merge them one after another.
-d or –delimiters=   replace tab character with specified interval character.
-s or –serial   serialize instead of parallel processing.

[ [emailprotected] awk]# seq 10|xargs -n 2> file

[ [emailprotected] awk]# seq 10-1 1|xargs -n 2> file1

xrags -n 2 [means that the number of each batch is 2, and the default interval is “”]

seq 10 -1 1 [means generating 10 numbers, output in reverse order, step size is 1]

[ [email protected] awk]# cat file1

2 3

4 5

6 7

8 9

1 0

< p>

[ [email protected] awk]# cat file |awk'{print $1}’

1

3

5

7

9

[ [email protected] awk]# awk'{print NR}’ file file1

1< /p>

2

3

4

5

6

7

8

9

10

[ [email protected] awk]# awk'{print NR,FNR}’ file file1

1 1

2 2

3 3

4 4

5 5

6 1

7 2

8 3

9 4

10 5

[ [emailprotected] awk ]#

[ [email protected] awk]# awk’NR==FNR{a[NR]=$1}NR!=FNR{print a[FNR],$2 }’file file1

1 93 75 57 39 1

[ [email protected] awk]#

Detailed explanation of awk:

Awk is a line processor: Compared with the advantages of screen processing, there will be no memory overflow or slow processing problems when processing large files. It is usually used for formatting Text information

Awk processing process: Process each line in turn, and then output

Special points:

$0 represents the entire current line

< p>$1 The first field in each line

NF The number of fields variable

NR The record number of each line, the number of records in each line, the number of records in multiple files increases

FNR Similar to NR, However, multi-file records do not increment, and each file starts from 1

Tab character

Line break

FS Define separator when BEGIN

RS The entered record separator, the default is a newline character (that is, the text is entered line by line)

~ Match, it is not an exact comparison with ==

< p>~ Mismatch, inaccurate comparison

== Equal, must all be equal, exact comparison

Not equal, exact comparison

&& Logic And

|| Logical OR

+ When matched, it means one or more than one

/[0-9][0-9]+/ Two One or more numbers

/[0-9][0-9]*/ One or more numbers

FILENAME file name

OFS output The field separator, which is also a space by default, can be changed to a tab character, etc.

The record separator output by ORS, the default is a newline character, that is, the processing result is also output to the screen line by line

-F'[:#/]’ Define three separators

[ [email protected] awk]# paste file3 file4

1 9

p>

3 7

5 5

7 3

9 1

[ [emailprotected] awk]# paste file3 file4|tr ” ” “”

1 9

3 7

5 5

7 3

9 1

The paste command will merge each file line by line, line by line.

-d or –delimiters=   replace tab character with specified interval character.

-s or –serial   serialize instead of parallel processing.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 518 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.