Getting Started with Linux (D) text processing and data traffic redirection

Content from "experimental building", after study documenting

1 simple text processing

1.1 tr command

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

1.2 col command

Tab will be converted to spaces -x
-h converting spaces to Tab

2 data stream redirects

2.1 redirected to a file

Create a file Documents / test.c, does not create hello.c file. Use the command:

$ cat Documents/test.c hello.c

We will complain, because there is no hello.c.
The standard output is redirected to a file, use the command:

# 将标准错误重定向到标准输出,再将标准输出重定向到文件,注意要将重定向到文件写到前面
$ cat Documents/test.c hello.c >somefile  2>&1
# 或者只用bash提供的特殊的重定向符号"&"将标准错误和标准输出同时重定向到文件
$ cat Documents/test.c hello.c &>somefilehell

At that point, somefile and somefilehell file content.

2.2 redirected to a file and terminal

Use the command:

$ echo 'hello shiyanlou' | tee hello

At this time, simultaneously the output terminal and the file contents in the hello

2.3 permanent redirect

Use a permanent redirect command exec, exec command role is to replace the current Shell command specified that the use of a process to replace the current process, or specify a new redirection:

# 先开启一个子 Shell
$ zsh
# 使用exec替换当前进程的重定向,将标准输出重定向到一个文件
$ exec 1>somefile
# 后面你执行的命令的输出都将被重定向到文件中,直到你退出当前子shell,或取消exec的重定向(后面将告诉你怎么做)
$ ls
$ exit
$ cat somefile

2.4 creates an output file descriptor

Here Insert Picture Description

2.5 close the file descriptor

$ exec 3>&-
$ cd /dev/fd;ls -Al;cd -

2.6 mask command output

Using the following command will not be any output

$ cat Documents/test.c 1>/dev/null 2>&1

3 color flame

$ sudo apt-get install caca-utils
$ cacaview <pic_file>
$ cacademo
$ cacafire

It generates color of the flame

Released four original articles · won praise 5 · Views 2020

Guess you like

Origin blog.csdn.net/fengyang182/article/details/104186181
Recommended