Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the csplit command in Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to use the csplit command in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The Linux common command csplit command is used to split a large file into small fragments and to save each fragment into a file.

Csplit splits a large file into small fragments

Add that the name of the fragmented file is similar to "xx00" and "xx01". The csplit command is a variant of split. Split can only split files according to file size or number of lines, but csplit can split files according to their own characteristics.

Syntax csplit (option) (parameter) option-b or-- suffix-format=: preset output format whose file name is xx00,xx01, etc., users can change the output file name by changing it;-f or-- prefix=: preset output header string whose file name is xx00,xx01, etc. If you set the output header string as "hello", the output file name will become hello00,hello, 01. -k or-- keep-files: keep the file, even if an error occurs or interrupt execution, and cannot delete the output saved file;-n or-- digits=: preset the number of output file names whose file name is xx00,xx01. If the user specifies that the number of output file names is "3", the output file name will become xx000,xx001, etc.;-Q or-s or-- quiet or-- silent: does not show instruction execution;-z or-- elide-empty-files: delete a file with a length of 0 Byte. Parameter files: specify the original file to split

Pattern: specifies the matching pattern when you want to split the file.

Example test file server.log

Cat server.log SERVER-1 [con] 10.10.10.1 suc [con] 10.10.10.2 fai [dis] 10.10.10.3 pen [con] 10.10.10.4 suc SERVER-2 [con] 10.10.10.5 suc [con] 10.10.10.6 fai [dis] 10.10.10.7 pen [con] 10.10.10.8 suc SERVER-3 [con] 10.10.10.9 suc [con] 10.10.10 .10 fai [dis] 10.10.10.11 pen [con] 10.10.10.12 suc needs to split server.log into server1.log, Server2.log 、 server3.log The contents of these files are taken from different SERVER sections of the original file:

[root@localhost split] # csplit server.log / SERVER/-N2-s {*}-f server-b "d.log"; rm server00.log [root@localhost split] # ls server01.log server02.log server03.log server.log command details:

/ [regular expression] / # matches the text style, such as / SERVER/, from the first line to the matching line containing SERVER. {*} # means that the split is repeated according to the match until the end of the file stops, specifying the number of times the split is performed in the form of {integer}. -s # silent mode, no other information is printed. -n # specifies the number of digits of the split file name suffix. For example, 01, 02, 03 and so on. -f # specifies the split file name prefix. -b # specifies the suffix format. D.log, for example, is similar to the printf parameter format in the C language. Rm server00.log # deletes the first file because the split first file has no content and the matching word is on the first line of the file. Thank you for reading! This is the end of this article on "how to use the csplit command in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report