Linux command cut, split, paste

Source: Internet
Author: User

cut extracts text and outputs

-D Specify delimiter
-C in Characters
The part of the-F partition after D

Example:
1-d and-F use
Remove to: As delimiter, part 2nd
[Email protected] tmp]# echo ni:hao|cut-d ":"-f2
Hao

2-c use
Take a 2nd character
[Email protected] tmp]# echo ni:hao|cut-c 2
I
Take 2 to 6 characters
[Email protected] tmp]# echo ni:hao|cut-c 2-6
I:hao
Takes a character before the 5th character and a character after the 5th character
[Email protected] tmp]# echo ni:hao|cut-c-5
Ni:ha
[Email protected] tmp]# echo ni:hao|cut-c 5-
Ao
The above characters or fields can be

Remove the 2nd and 5th characters
[Email protected] tmp]# echo ni:hao|cut-c 2,5
Ia

Split split file

-b Specifies the size after splitting
-l Specifies the number of rows after splitting
-a specifies the suffix length, which defaults to 2 bits
-D uses a numeric suffix, which is the letter suffix by default, starting with a

Example:

1-b use (followed by K, M or K, M, G)
10M size split per file Maillog
[Email protected] tmp]# split-b 10m maillog
[Email protected] tmp]# LL-H|TAC
-rw-r--r--1 root root 8.1M June 09:18 Xac
-rw-r--r--1 root root 10M June 09:18 Xab
-rw-r--r--1 root root 10M June 09:18 Xaa

2 in 30 behavior units, split the passwd file, the split file begins with new
[Email protected] tmp]# split-l passwd New
[Email protected] tmp]# LS-LTR|TAC
-rw-r--r--1 root root 1370 June 09:26 Newaa
-rw-r--r--1 root root 1501 June 09:26 Newab
-rw-r--r--1 root root 1513 June 09:26 NEWAC
-rw-r--r--1 root root 1493 June 09:26 Newad
-rw-r--r--1 root root 1097 June 09:26 Newae

3 split the passwd in 50 rows, the file begins with a PA and is suffixed with a 3-digit number
[Email protected] tmp]# split-l 50-da3 passwd pa
[Email protected] tmp]# LL-RT|TAC
-rw-r--r--1 root root 2363 June 09:32 pa000
-rw-r--r--1 root root 2542 June 09:32 pa001
-rw-r--r--1 root root 2069 June 09:32 pa002

Paste Merging Files
-d Specifies the merged delimiter
-S consumes one row per file

Example:
1-d Example
[email protected] tmp]# cat paste1 Paste2
A
B
C
1
2
3
Simple merge
[email protected] tmp]# paste paste1 paste2
A 1
B 2
C 3

Use-D to specify: to separate the compliant and
[Email protected] tmp]# paste-d: paste1 paste2
A:1
B:2
C:3

-S use (after merging, each file occupies one line)
[Email protected] tmp]# paste-s paste1 paste2
A b C
1 2 3

Linux command cut, split, paste

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.