awk accepts data from stdin by default, printing text to stdout.
Default input and output delimiters for awk:
FS: Enter field delimiter, default space.
RS: Enter line delimiter, default \ n.
OFS: Output field delimiter, default space.
ORS: Output line delimiter, default \ n.
Example: Make multiple rows into a row by changing the default built-in variable
File.txt (the number of information bars for each person is not sure, the distinction is a blank line)
Pedestrian Armor
Tel: 13777707771
Mobile: 010-12345678
Passers-by B
Tel: 13912344321
Mobile: 010-56784321
qq:87654221
To change the format to:
Passers-by phone: 13777707771 Mobile: 010-12345678
Passerby B Tel: 13912344321 Mobile: 010-56784321 qq:87654221
Give the final order first, then look at the analysis.
awk ' begin{fs= ' \ n '; Rs= ""; ors= ""}{for (x=1;x<=nf;x++) {print $x "\ T"} print "\ n"} './t.txt
Analysis:
Change FS to \ n so that read into the domain is a line, and then change the RS to "", so that a person's information read into a line. Now it's two rows of data. The next step is the output.
Because the default OFS is the space, Ors is \ n, that's what we want, so
' begin{fs= "\ n"; Rs= ""}{print $1,$2,$3,$4}' ./t.txt
The result of the output is:
Passers-by phone: 13777707771 Mobile: 010-12345678
Passerby B Tel: 13912344321 Mobile: 010-56784321 qq:87654221
That's what we want, but it's not a good idea to output to $4, assuming that a person's record is more than 4 rows.
At this point I want to print the $1,$2,$3,$4 directly, and print is not the same, but the result is:
' begin{fs= "\ n"; Rs= ""}{print $}' ./t.txt
Pedestrian Armor
Tel: 13777707771
Mobile: 010-12345678
Passers-by B
Tel: 13912344321
Mobile: 010-56784321
qq:87654221
It's a little different from what you want, why? because OFS does not work when the output is $, OFS is only used when outputting multiple fields to be inserted between each domain.
Then I thought I'd use a for loop to print out every field in each row. So
' begin{fs= "\ n"; Rs= ""}{for (x=1;x<=nf;x++) {print $x}}' ./t.txt
Pedestrian Armor
Tel: 13777707771
Mobile: 010-12345678
Passers-by B
Tel: 13912344321
Mobile: 010-56784321
qq:87654221
The result seems to have changed, because each print for the for loop will output a ORS, and you can specify a visible ors to try and know.
So you need to specify ORS as "" and manually output line breaks. This is the very beginning of the order.
awk changes the input and output delimiter instance analysis