CentOSsed command to process text files

Source: Internet
Author: User
Cattest.txt 12341. Merge the upper and lower rows of sed & #39; $! N; s/\ n/\ t/&%39;test.txt 12342. merge matching mode and the next sed & #39;/2/{N; s/\ n/\ t/Jun 'test.txt 12343. merge all rows of sed & #39;: a; N; s/\ n //; ba; & #3

Cat test.txt

1
2
3
4
1. Merge the upper and lower rows
Sed '$! N; s/\ n/\ t/'test.txt

1 2
3 4
2. Merge matching mode and its next row
Sed '/2/{N; s/\ n/\ t/}' test.txt

1
2 3
4
3. Merge all rows
Sed ': a; N; s/\ n //; ba; 'test.txt

1 2 3 4

4. interactive parity rows
Sed '$! N; s/\ ([^ \ n] * \) \ n \ ([^ \ n] * \)/\ 2 \ n \ 1/'test.txt

2
1
4
3
6
5

5. delete empty rows
Sed '/^ $/d' test.txt

6. delete multiple empty rows.
Sed '/^ $/{N;/^ \ n * $/D}' test.txt

7. add blank lines after each row
# Cat test.txt | sed G
1

2

3

4

5

6

8. delete empty rows (that is, delete all even rows)
Sed 'n'; D'

9. multiple mkdir directories
DIR = 'SED ': a; N; s/\ n //; ba; 'test.txt'
Mkdir $ DIR
Create five directories, 1, 2, 3, 4, and 5 (the directory cannot be created using MPs queue)


Related Article

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.