Linux: split and Paste command

Linux: split command

  • If you want to divide a file into a number of files which contain certain number of lines of the original file then you can use the split command. Let us consider the following example which will split the file named bigfile into smaller files each having 100000 lines and with a default file names as xaa, xab, xac, xad and so on. The parameter –l specifies the number of lines to be present in each of the divided file.

  • Example: split -l 100000 bigfile-

  • You can also give meaningful names to the divided files. In the following example each of the divided file is given the name mgm_aa, mgm_ab, mgm_ac and so on.

  • Example: split –l 100000 bigfile mgm_

  • You can also split a binary file such as movies and mp3 files. In the following example command will split the WMV file, kabalspean.wmv, into a series of 15 kilobyte chunks and name them kbs_aa, kbs_ab, kbs_ac and so on.

  • Example: split -b 15k kabalspean.wmv kbs_

  • These created smaller files can again be concatenated using the cat command. This cat command can be used to restore all smaller chunks into original text file or binary. In the following example smaller chunks of kbs_aa, kbs_ab and kbs_ac is concatenated into a new file named as kabalspean_new.wmv

  • Example: cat kbs* >kabalspean_new.wmv

Linux: Paste command

  • Linux paste command can be used to merge corresponding or subsequent lines of files

Syntax: paste [-s] [-d list] file

  • Consider the following file example1.txt which has the content as given below

Content of file example1.txt


  • Consider another file example2 and the content of it is as given below

Content of file example2.txt

how are you?

  • In the following example the paste command is used for merging the contents of corresponding lines of example1.txt and example2.txt into a new file named as example3.txt

Example: paste example1.txt example2.txt > example3.txt

The output of example3.txt

Hello how are you
Me fine
Thank you

Note: if you use –s option then one file will be pasted after the other.

iLinux: Compressing-Decompressing, ps, kill, and su commands << Previous
Next>> SSH Connections in LINUX / UNIX Based Systems

Our aim is to provide information to the knowledge seekers. 

comments powered by Disqus