Linux Basic Three

Source: Internet
Author: User

Handling of simple text 1.tr commands

The TR command can be used to delete some text from a piece of textual information. or convert it.

How to use:
tr [option]...SET1 [SET2]
The common options are:
Options Description
-d Delete and Set1 matching characters, note that not all words match or match by character order
-s Removes set1 specified characters that are contiguous and repeated in the input text

Examples of operations:
# 删除 "hello shiyanlou" 中所有的‘o‘,‘l‘,‘h‘$ echo ‘hello shiyanlou‘ | tr -d ‘olh‘# 将"hello" 中的ll,去重为一个l$ echo ‘hello‘ | tr -s ‘l‘# 将输入文本,全部转换为大写或小写输出$ cat /etc/passwd | tr ‘[:lower:]‘ ‘[:upper:]‘# 上面的‘[:lower:]‘ ‘[:upper:]‘你也可以简单的写作‘[a-z]‘ ‘[A-Z]‘,当然反过来将大写变小写也是可以的

2.col command

The col command can be Tab built with a number of equivalent spaces, or reverse the operation.

How to use:
col [option]
The common options are:
Options Description
-x will be Tab converted to spaces
-h Convert a space to Tab (the default option)
Examples of operations:
# 查看 /etc/protocols 中的不可见字符,可以看到很多 ^I ,这其实就是 Tab 转义成可见字符的符号$ cat -A /etc/protocols# 使用 col -x 将 /etc/protocols 中的 Tab 转换为空格,然后再使用 cat 查看,你发现 ^I 不见了$ cat /etc/protocols | col -x | cat -A

3.join command

Users who have studied the database should not be unfamiliar with this, and this command is used to merge the same line that contains the same content in two files.

How to use:
join [option]... file1 file2
The common options are:
Options Description
-t Specify delimiter, default is space
-i Ignore Case differences
-1 Indicates which field the first file is to compare with, and the default compares the first one
-2 Indicates which field to use for the second file, and by default compares the first one
Examples of operations:
# 创建两个文件$ echo ‘1 hello‘ > file1$ echo ‘1 shiyanlou‘ > file2$ join file1 file2# 将/etc/passwd与/etc/shadow两个文件合并,指定以‘:‘作为分隔符$ sudo join -t‘:‘ /etc/passwd /etc/shadow# 将/etc/passwd与/etc/group两个文件合并,指定以‘:‘作为分隔符, 分别比对第4和第3个字段$ sudo join -t‘:‘ -1 4 /etc/passwd -2 3 /etc/group

4.paste command

pasteThis command join is similar to a command, which simply merges multiple files together to separate them without comparing the data Tab .

How to use:
paste [option] file...
The common options are:
Options Description
-d Specifies the merged delimiter, which is tab by default
-s Do not merge to one line, one row for each file
Examples of operations:
echo hello > file1$ echo shiyanlou > file2$ echo www.shiyanlou.com > file3$ paste -d ‘:‘ file1 file2 file3$ paste -s file1 file2 file3

Third, summary

The above commands are not all you will often use, but they are very practical, skilled, can alleviate a lot of work, such as the use of mouse operations in the gedit copy paste assignment paste, the contents of two files into a file, which originally only need a command to complete.

Linux Basic Three

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.