Add two files in linux

Source: Internet
Author: User
In linux, add the content of two files-general Linux technology-Linux programming and kernel information. For details, refer to the following section. A.txt
0 3
0 9
0 10
0 8
0 10
0 14
0 7
0 10
2 5
0 8

B .txt
1 80
1 68
0 118
24 187
1 120
68 213
5 125
197 223
7 141

Use SHELL to add the same fields of the two files: A. txt + B .txt:
1 83
1 77
1 127
......

The solution is as follows:
I,
Awk 'nr = FNR {a [NR] = $1; B [NR] = $2}
NR> FNR {print $1 + a [FNR], $2 + B [FNR]} 'a.txt B .txt

II,
While read-u3 a B & read-u4 c d; do
Echo $ (a + c) $ (B + d ))
Done 3 Newfile

III,
Awk '{print $1 + $3 "" $2 + $4}' <(paste file1 file2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.