Learn a Linux command every day (30): cut

Brother of migrant workers 2021-02-23 18:21:26
learn linux command day cut


Command profile

cut Split the contents of the line in the file by the specified separator and output .

cut Commands can also be used to delete specified lines or segments in a file , Then print out the changes . It may also be used to splice file contents into a new file , Function and cat similar .

Command format

cut [ Options ] [ Link file name ]
cut [OPTION] [LINKNAME]

Option description

-b # Only display the specified ( Number of bytes ) The content of
-c # Only display the specified ( Number of characters ) The content of
-d # Specifies the separator for the field , The default is “TAB”
-f # Print the specified fields ( Column ) The content of
-n # And “-b” Option combination , Don't split multibyte characters
-s # Don't print the contents of lines that don't contain delimiters
--help # Print help
--version # Print version information

cut The description of the byte or character range specified in the command is as follows :

N # from 1 byte 、 The character or field starts at N Bytes 、 Character or field
N- # From N Bytes 、 Character or field to the end of the line
N-M # From N Bytes 、 Character or field to M Bytes , Character or field
-M # From 1 Bytes 、 Character or field to M Bytes 、 Character or field
Be careful : All range values need to be integers , Such as :10,10-,10-20,-20.

Application, for example,

# Print a specified number of bytes of content
[root@centos7 testdir]# cat mingongge1.txt
1111 11 111111 1 111 1 1 11
22222222222 222 2222 22 2 2 2
33333333333 333333 3333 333 33
444444444444 444 444444444
[root@centos7 testdir]# cut -b 3 mingongge1.txt
1
2
3
4
# Intercepts the contents of the specified field
[root@centos7 testdir]# cat cuttest.txt
1 2 3 4 5 6 8
9 8 7 6 5 4 3
2 1 9 8 7 6 5
# Separated by spaces , Print the first column of each row
[root@centos7 testdir]# cut -f1 -d" " cuttest.txt
1
9
2
# Separated by spaces , Print the first and third columns of each row
[root@centos7 testdir]# cut -f1,3 -d" " cuttest.txt
1 3
9 7
2 9
# Separated by spaces , Print the third column of each row to the end
[root@centos7 testdir]# cut -f3- -d" " cuttest.txt
3 4 5 6 8
7 6 5 4 3
9 8 7 6 5
# Intercept every line at 2-5 Characters
[root@centos7 testdir]# cut -c 2-5 cuttest.txt
2 3
8 7
1 9
# Intercept the first to fifth characters of each line
[root@centos7 testdir]# cut -c -5 cuttest.txt
1 2 3
9 8 7
2 1 9
# Intercept the fifth to last character of each line
[root@centos7 testdir]# cut -c 5- cuttest.txt
3 4 5 6 8
7 6 5 4 3
9 8 7 6 5

Specifying the use of the separator to intercept content is very practical , It's often used at work .

This article is from WeChat official account. - The road of technology for migrant workers (jishuroad) , author : Click to follow ????

The source and reprint of the original text are detailed in the text , If there is any infringement , Please contact the yunjia_community@tencent.com Delete .

Original publication time : 2021-01-27

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .

版权声明
本文为[Brother of migrant workers]所创,转载请带上原文链接,感谢
https://javamana.com/2021/02/20210223181920967m.html

  1. JAVA的函数式接口
  2. JAVA里的元祖类
  3. JQuery Gantt package to create a new ASP.NET project
  4. Binary conversion of Unicode code (Java)
  5. The functional interface of Java
  6. Yuanzu class in Java
  7. Java中的CPU占用高和内存占用高的问题排查
  8. HashMap连环问你能答出几道?
  9. IntelliJ IDEA 还能画思维导图,果然最强 IDE!
  10. java中的反射和代理
  11. Troubleshooting of high CPU and memory usage in Java
  12. How many questions can you answer?
  13. IntelliJ idea can also draw mind maps. It's really the strongest ide!
  14. Reflection and proxy in Java
  15. Java中的CPU占用高和内存占用高的问题排查
  16. Linux OOM(out of memory)
  17. mysql 自定义函数因参数名称报错
  18. Troubleshooting of high CPU and memory usage in Java
  19. Linux OOM(out of memory)
  20. MySQL user defined function error due to parameter name
  21. echarts-gl 3D 地图柱状图可视化GDP
  22. Visualization of histogram of ecarts GL 3D map
  23. 金三银四如何应对Redis面试,一文深入Redis实战实践!
  24. 阿里资深架构师定制金三银四面试整理出来的一份Java核心知识点.pdf
  25. 为什么Java开发工程师工资高,却很多人想转行?
  26. How to deal with the interview of redis!
  27. Ali senior architect customizes a Java core knowledge point sorted out in the interview of golden, silver and four.pdf
  28. Why do java development engineers have high salaries, but many people want to change careers?
  29. 用注解开发SpringMVC
  30. Developing spring MVC with annotations
  31. 编译redis报错/deps/hiredis/libhiredis.a解决
  32. Compile redis report error / DEPs / hirredis / libhirredis. A solution
  33. 用注解开发SpringMVC
  34. Developing spring MVC with annotations
  35. Spring学习笔记-01
  36. Centos安装和卸载docker
  37. Spring learning notes-01
  38. Installing and uninstalling docker in CentOS
  39. Java基础-异常
  40. Java基础-反射
  41. Java基础-继承
  42. k8s部署 (进行中)
  43. Hive-常见调优方式 && 两个面试sql
  44. 死磕Spring之IoC篇 - BeanDefinition 的加载阶段(XML 文件)
  45. Java basics exception
  46. Java Basics - Reflection
  47. Java Basics - inheritance
  48. K8s deployment (in progress)
  49. Hive common tuning methods & two interview SQL
  50. The loading phase of beandefinition (XML file)
  51. 死磕Spring之IoC篇 - BeanDefinition 的加载阶段(XML 文件)
  52. Hive-常见调优方式 && 两个面试sql
  53. The loading phase of beandefinition (XML file)
  54. Hive common tuning methods & two interview SQL
  55. iconv文件编码转换由windows文件放到linux下
  56. The code conversion of iconv file is put into Linux by windows file
  57. SpringBoot2+intellij IDEA开发前环境准备
  58. Preparation of pre development environment for springboot2 + IntelliJ idea
  59. Docker私有仓库部署
  60. Docker private warehouse deployment