- Outline
- Brief shell command line tool cut
- background
- Occasionally need to use awk to filter specific columns
- awk is a very powerful
- But behind the powerful, but along with the complex
- In fact, the same function, awk is not much complicated
- If it is a simple task, cut tool is completely capable of
- Specific locations within the cutting line
- Specific field within the cutting line
- Description may not be accurate, the following will be an example
- Occasionally need to use awk to filter specific columns
1. Prepare
- the
- centos7
- file
cutdemo01
1:2:3:4:5 1:2:3:4:5 1:2:3:4:5
cutdemo02
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
2. Scene 1: specific locations within the cutting line
- Outline
- I want specific characters within the cut line
command
Command 1: Cutting a single character
# -c 表示切割行内的 特定字符 # 下标从 1 开始 # 如果超出范围, 会返回 空内容 > cut -c1 cutdemo01 1 1 1
Command 2: Cutting consecutive characters
# 下标从 1 开始, 3 结束 > cut -c1-3 cutdemo01 1:2 1:2 1:2
Command 3: Cutting discontinuous character
# 下标从 1 开始, 3 结束, 外加第 5 个字符 > cut -c1-3,5 cutdemo01 1:23 1:23 1:23
3. Scenario 2: endo Branch specific field
- Outline
- Similar cutting mode of awk
- command
Under certain field delimiter cut: Command 1
-d 指定分隔符 -f 指定字段 > cut -d':' -f 1 cutdemo01 1 1 1
Cutting the continuous fields specific delimiter: Command 2
# -f 类似 之前的 -c # 结果中, 每个字段, 会用 -d 指定的分隔符隔开 > cut -d':' -f 1-3 cutdemo01 1:2:3 1:2:3 1:2:3
Discontinuous fields under certain cutting delimiter: Command 3
> cut -d':' -f1-3,5 cutdemo01 1:2:3:5 1:2:3:5 1:2:3:5
- doubt
- If you use the tab breakdown, the command-line play no tab, use \ t escape not so that, how to do
- You can take a look at the man command
- Without -d, the default is to use the tab to points
- You can take a look at the man command
- If you use the tab breakdown, the command-line play no tab, use \ t escape not so that, how to do
- pit
- cut in only one character as a delimiter
- So there may be two possible Xiahuikeng
- Continuous need more characters, as delimiters
- Simultaneous use of multiple characters, as delimiters
- solve
- Use awk
- So there may be two possible Xiahuikeng
- cut in only one character as a delimiter
ps
- ref
- Linux Shell Scripting --cut command
- It very simple
- The difference between the cut and awk
- To the point of inspiration, made me realize the power of awk
- Linux Shell Scripting --cut command
- Recently restless, I do not know what to write
- Before things get to stopgap
- Charge a small one ...
- Before things get to stopgap