GNU/Linux Command – CSPLIT

csplit — Split the files into pieces based on a Context

Summary:
CSplit will read the input file and write into number of files as per the option given to it. By default, output file names will start with the prefix ‘xx’ and followed by the 2 suffix characters (aa, ab,..,zz). Suffix length can be changed. During the splitting, it will print the number of characters written into each file.

Examples:
$ csplit file /section/ -- Split the file into two parts. Part one is content before the 1st occurrence of word "section" and part two is content after that.

$ csplit -z file /section/ -- Same above. It will not create zero size output file.

$ csplit file /one/ /two/ /three/ -- Split the file into 3 parts.

$ csplit myfile 10 40 80 -- 1st file contains 1-9 lines, 2nd 10-39, 3rd 40-79 and 4th 80-EOF.

$ csplit myfile %India% -- Skip upto, but not the matching line and copy the remaining into a file.

$ csplit myfile /India/ -- Copy upto, but not the matching line to 1st file and remaining in 2nd file.

$ csplit myfile /India/ {*} -- Every occurrence of the pattern"India" is the splitting point.

$ csplit myfile /India/ {6} -- Only first 6 occurrences of the pattern "India" is the splitting point.

Read : man csplit

Advertisements
Tagged with: ,
Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: